hello,
i have a bunch of files w/ numerals as extensions(eg: 'filename.1120',
'filename.1121', 'filename.1125'). i wanted to change all their extensions
to '.pl' like ('filename1120.pl', 'filename1121.pl'...etc.). i tried the
script below, it seems to work but it doesn't execute the last rename
command and kept getting the error message: No such file or directory. the
funny thing is that i do have the files and directories present and perl can
even find it by printing them out for me.

what am i missing?
thanks in advance.

use strict;
use File::Find;

my $Extension_Old = '\d\d\d\d';
my $Extension_New = 'pl';
my @Files;

while (<DATA>) {
 chomp;
 my $path = "d:/$_";
 print "$path\n";
 &find(\&wanted, $path);
}
my $count = $#Files; $count +=1;
print "...$count file/s found\n";

foreach my $file (@Files) {
 my $newname = uc($file);
 $newname =~ s/(.*?)\.($Extension_Old)/$1$2\.$Extension_New/i;
 print "Renaming file: \"$file\" to..\t$newname\n";
 rename ($file, $newname) or warn "Couldn't rename $file to $newname: $!\n";
}

sub wanted {
 return if -d $_;
 (my $ext = $_) =~ s/^.*\.(.*?)$/$1/;
 return if $ext !~ /$Extension_Old/
 push(@Files, $_)
}

__DATA__
Perl/LWPExamples

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to