[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Rename Problem [Novice Question]



I know I must be missing something simple, but the following
script is not working for me.  The script should read the
file names in a folder and normalize them with substitute
and rename.  The script runs without incident, but the files
are not renamed.  Can anyone help me with this problem?


===Russell Erik Johannesson [russell@critpath.org]

______________________________________________________________
#!perl
# Note: This program renames files to eliminate
# spaces before and after hyphens and dashes, and
# replaces varies dashes and hyphens with em-dashes.

$dir='Macintosh HD:Sample Folder:';
print "$dir\n";
opendir(FOLDER,"$dir") || die "I could not open this folder:";
@files=readdir(FOLDER);
for (@files) { 
        $oldname=$_;
        s/(.*)\s+[-QP]\s*(.*)/$1Q$2/;
        s/(.*)\s*[-QP]\s+(.*)/$1Q$2/;
        print "$oldname\t$_\n";
        rename($oldname,$_); 
}
closedir(FOLDER);