User Tools

Site Tools


utilities

This is an old revision of the document!


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 {code perl} use strict; &renameFiles( &getArgs() );

  1. ——————- 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 );
 }

} {/code}

utilities.1416792309.txt.gz · Last modified: 2014/11/24 01:25 by ben