7 my $PROGRAM = 'rename-all.pl';
8 my $USAGE = "Usage: $PROGRAM regex substitution [directory]\n\nUses Perl regular expressions to rename multiple files. For example, to change the extension of all files ending with 'TXT' to 'txt':\n\n\t$PROGRAM 'TXT\$' txt\n";
10 unless( $#ARGV >= 1 ) { die $USAGE; }
12 my $old = shift @ARGV;
13 my $new = shift @ARGV;
23 opendir( DIR, $dir ) || die( "Cannot open directory: $!\n" );
24 my @files = readdir(DIR);
29 for my $file (@files) {
30 if( -f $file && $file =~ /$old/ ) {
32 $file =~ s/$old/$new/;
33 print "mv $oldfile $file\n";
34 move( $oldfile, $file );