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.


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

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
    Many thanks Chady, this was my first effort at developing a script, and using another snippet.

    Joe

    Your prose: " He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life."
    Very applicable in my case!!

Testing Renaming and moving files to a subdirectory
by Joes (Acolyte) on Jul 13, 2001 at 11:46 UTC
    Sorry Chady,the compilation was aborted because of 3 errors "Requiring Explicit Package Names" :
    @files at line 11
    $file at line 14
    $newDir at line 18

    Can you shed some light on this for me please?

    Many thanks,
    Joe, Townsville