User Tools

Site Tools


utilities

Utilities

TV episode renaming script

This perl script, or win32 binary offers a comprehensive solution for automatically renaming files belonging to a TV series. http://www.robmeerman.co.uk/coding/file_renamer

MP3 Renamer and Organiser script

Regex file renamer

renrx.pl from http://www.perlmonks.org/?node_id=311703

use strict;
&renameFiles( &getArgs() );
 
  - ------------------- SUBROUTINES -------------------
sub printUsage {
   print <<EOF;
   Usage:
      > perl renrx.pl ["<regex>" [<preview>]]
 
      Where,
      * <regex> the regular expression to use
      * <preview> is 0 to disable preview; anything otherwise
EOF
}
 
sub getArgs {
   my ($reg, $prompt) = ("", 1);
   if ( @ARGV == 2 ) {
      ($reg, $prompt) = @ARGV;
      unless ( $prompt == 0 ) { $prompt = 1; }
   } elsif ( @ARGV == 1 ) {
      ($reg) = @ARGV;
   } else {
      # unexpected number of args
      &printUsage();
      exit;
   }
   return ($reg, $prompt);
}
 
sub renameFiles {
   my ($reg, $prompt) = @_;
   my @files = <*>;
   foreach  (@files) {
      my $before = $_;
      eval $reg;
      my $after = $_;
      if ( $before eq $after ) { next; } # nothing to do
      if ( $prompt ) {
         print "$before => $after\n";
         print "Rename? [[Yes|No|Always|Cancel]] ";
         chomp (my $resp = <STDIN>);
         if ( $resp =~ m/^y/i ) {
            # do nothing
         } elsif ( $resp =~ m/^n/i ) {
            next;
         } elsif ( $resp =~ m/^a/i ) {
            $prompt = 0;
         } elsif ( $resp =~ m/^c/i ) {
            exit;
         } else {
            print "Invalid choice.\n";
            exit;
         }
      } # if prompt
      rename( $before, $after );
   }
}
utilities.txt · Last modified: 2014/11/24 01:27 by ben