# rename filenames using search and replace
# Usage: rename perlexpr [files]
# file:///J:/sw/file_renaming/Renaming%20Files%20with%20Perl.htm
# includes *nix version.
# eg on windows: perl rn.pl "s/searchfor/replacewith/" *
# in nix, you may need to use ' ' instead
use File::Glob qw

glob); # needed if you want this to work on windows
use warnings;
($regexp = shift @ARGV) || die "Usage: eg on windows: rn.ple \"s/oldtext/newtext/\" *".
"\n Case sensitive by default.\n";
if (!@ARGV) {
@ARGV = <STDIN>;
chomp(@ARGV);
}
foreach $_ (bsd_glob(@ARGV, GLOB_NOCASE)) {
$old_name = $_;
eval $regexp;
die $@ if $@;
rename($old_name, $_) unless $old_name eq $_;
print "$_\n" unless $old_name eq $_; # enable this if you want to see the renamed files listed
}
exit(0);