Created
June 10, 2015 15:01
-
-
Save siddharthkrish/669633b4938c06cc3b2f to your computer and use it in GitHub Desktop.
rename folders & files of tv series to S00E00[.ext] format
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use File::Copy qw(move); | |
my $directory = '.'; | |
opendir (DIR, $directory) or die $!; | |
while (my $file = readdir(DIR)) { | |
if (!($file =~ m/^\./i)) { | |
my $clean = $file; | |
# name has to be of the format *SxxExx* | |
if (-d $file) { | |
$clean =~ s/.*([sS][0-9]+[eE][0-9]+).*(\..*$)*/$1/g; | |
} else { | |
$clean =~ s/.*([sS][0-9]+[eE][0-9]+).*(\..*$)/$1$2/g; | |
} | |
# rename filename if it has changed. | |
if ("$file" ne "$clean") { | |
move $file, $clean; | |
print "$clean \n"; | |
} | |
} | |
} | |
closedir(DIR); | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment