[oak perl] file renaming script

Sandy Santra santranyc at yahoo.com
Tue Feb 15 23:19:12 PST 2005


I've used this script to rename directories on a Win98 machine.  (Apologies 
in advance for not scoping my variables.)  Is there a line of code or 
switch or something I can add that would make it *also* operate on every 
file within each directory it's processing?  Thanks.

## find [text string] and delete it from all file and directory names in a 
directory

chdir "c:/[directoryname]" or die "cannot chdir to that directory: $!";
foreach $file (glob "*") {
         $newfile = $file;
         $newfile =~ s/%2f/_/;
         if (-e $newfile) {
                 ## warn "can't rename $file to $newfile: $newfile exists\n";
         } elsif (rename $file, $newfile) {
                 ## success, do nothing
         } else {
                 warn "rename $file to $newfile failed: $!\n";
         }
}

--Sandy Santra



More information about the Oakland mailing list