Skip to content

Instantly share code, notes, and snippets.

@davidreuss
Created February 3, 2012 23:04
Show Gist options
  • Save davidreuss/1733547 to your computer and use it in GitHub Desktop.
Save davidreuss/1733547 to your computer and use it in GitHub Desktop.
pvr-cleanup -- for a friend.
<?php
$root = dirname(__FILE__);
$pvr_record_folder = "{$root}/PVRRECORD";
$will_rename = array();
$count_map = array();
foreach (glob("${pvr_record_folder}/*.pvr", GLOB_ONLYDIR) as $folder) {
$folder = basename($folder);
$new = preg_replace(
'/^\d{4}-(\d{2})(\d{2})-\d{4}-(.*)\.pvr$/', '\2\1-\3', $folder);
if (!isset($will_rename[$new])) {
$will_rename[$new] = $folder;
$count_map[$new] = 1;
} else {
$will_rename[$new . '_' . $count_map[$new]] = $folder;
$count_map[$new]++;
}
}
foreach ($will_rename as $new => $old) {
$from = "$pvr_record_folder/${old}";
$to = "${pvr_record_folder}/${new}";
if (!rename($from, $to)) {
$action = 'FAILED';
} else {
$action = 'SUCCESS';
}
echo "$action: ${old} -> ${new}\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment