Skip to content

Instantly share code, notes, and snippets.

@siddharthkrish
Created June 10, 2015 15:01
Show Gist options
  • Save siddharthkrish/669633b4938c06cc3b2f to your computer and use it in GitHub Desktop.
Save siddharthkrish/669633b4938c06cc3b2f to your computer and use it in GitHub Desktop.
rename folders & files of tv series to S00E00[.ext] format
#!/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