in reply to Renaming and moving files to a subdirectory
umm.. let's see... here's a modified version with comments:
#!/usr/bin/perl -w use strict; my $dir = "c:/Xwords/"; # my $n=length "c:/Xwords/"; # why do you need this? my $newDir = "c:/Xwords/PrintedXwords/"; my @files; # you're better off doing this: opendir DIR, $dir or die "Cannot open directory: $!\n"; @files = grep {/\.puz$/i} readdir (DIR); close DIR; foreach my $file (@files) { my $new = $file; my $from = $dir . $file; $new =~ s/\.puz$/A\.puz/; my $to = $newDir . $new; print " \n \n"; print " full name of original file is $from \n"; print " name of original file is $file \n"; print " full name of new file is $to\n"; print " \n \n"; rename $from, $to; } print "Files renamed !";
Update: fixed declarations.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Renaming and moving files to a subdirectory
by Joes (Acolyte) on Jul 13, 2001 at 11:29 UTC | |
|
Testing Renaming and moving files to a subdirectory
by Joes (Acolyte) on Jul 13, 2001 at 11:46 UTC |