Created
July 17, 2015 13:59
-
-
Save zoka123/a513dd3f6909ab84f5e6 to your computer and use it in GitHub Desktop.
Rename .srt files to match .avi filenames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$files = scandir(__DIR__); | |
$pairs = array(); | |
foreach($files as $file){ | |
$type = null; | |
if (strpos($file,'.srt') !== false) { | |
$type = 'srt'; | |
} | |
if (strpos($file,'.avi') !== false) { | |
$type = 'avi'; | |
} | |
if($type === null){ | |
continue; | |
} | |
preg_match("/.*(S\d+E\d+).*/", $file, $res); | |
if(isset($res[1])){ | |
$pairs[$res[1]][$type] = $file; | |
} | |
} | |
foreach($pairs as $episode => $pair){ | |
$oldName = $pair['srt']; | |
$newName = $pair['avi']; | |
$newName = str_replace('.avi', '.srt', $newName); | |
echo 'Renaming ' . $oldName . ' to ' . $newName . PHP_EOL; | |
rename($oldName, $newName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment