X-Git-Url: http://git.projectaon.org/?p=project-aon.git;a=blobdiff_plain;f=common%2Fscripts%2Frename-all.pl;fp=common%2Fscripts%2Frename-all.pl;h=f48848470df17c8fc8c08a2d30c061ec4a56989e;hp=0000000000000000000000000000000000000000;hb=f4bdee5083ca9a72713637e1e979aa183e06faea;hpb=97545603aea8298f1eceb604ff65085cc7adfced diff --git a/common/scripts/rename-all.pl b/common/scripts/rename-all.pl new file mode 100755 index 0000000..f488484 --- /dev/null +++ b/common/scripts/rename-all.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w + +use strict; +use File::Copy; +use Cwd; + +my $PROGRAM = 'rename-all.pl'; +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"; + +unless( $#ARGV >= 1 ) { die $USAGE; } + +my $old = shift @ARGV; +my $new = shift @ARGV; +my $dir = ''; + +if( $#ARGV >= 0 ) { + $dir = shift @ARGV; +} +else { + $dir = getcwd; +} + +opendir( DIR, $dir ) || die( "Cannot open directory: $!\n" ); +my @files = readdir(DIR); +closedir(DIR); + +print $old; + +for my $file (@files) { + if( -f $file && $file =~ /$old/ ) { + my $oldfile = $file; + $file =~ s/$old/$new/; + print "mv $oldfile $file\n"; + move( $oldfile, $file ); + } +}