Joes has asked for the wisdom of the Perl Monks concerning the following question:
I have plagiarised tachyon's snippet for renaming files
My modification does not work, and I would appreciate any comments and assistance.
I have left the debugging print statement in, in case anyone wants to set up a dummy folder with some .puz files and an empty subdirectory
Many thanks,
Joe, Townsville
#!/usr/bin/perl -w use strict; my $dir = "c:/Xwords/"; my $n=length "c:/Xwords/"; # There must be a better way of doing t +his => Please?? my $from = '.puz'; my $to = 'A.puz'; my $newdir = "c:/Xwords/PrintedXwords/"; while (<$dir*$from>) { # checking for .puz files my ($old,$new,$full); # declaring variables $old = $full = $_; # setting the full filename and path $new = $old = substr $_,$n; # removing the path details of + filename $new =~ s/$from$/$to/; # changing the old file name print " \n \n"; print " full name of original file is $full \n"; print " name of original file is $old \n"; print " full name of new file is {$newdir.$new} \n"; # does not co +ncatenate - leaves the '.' visible print " \n \n"; rename $full, {$newdir.$new}; } print "Files renamed !"; exit
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Renaming and moving files to a subdirectory
by tachyon (Chancellor) on Jul 13, 2001 at 11:59 UTC | |
|
Re: Renaming and moving files to a subdirectory
by Chady (Priest) on Jul 13, 2001 at 10:56 UTC | |
by Joes (Acolyte) on Jul 13, 2001 at 11:29 UTC | |
by Joes (Acolyte) on Jul 13, 2001 at 11:46 UTC |