SteveS832001 has asked for the wisdom of the Perl Monks concerning the following question:

This script moves file from my computer to a mapped
drive k:/. when it runs it will move the first file
but skips over the rest of the files is there a reason for this
I also need to know how to fix it too
# # # moves the ATM files from the c: to c:\atm and renames them with t +he # current date. # # use File::Copy; @files = ("ATMCAF00", "ATMCAF01", "ATMCAF12", "ATMCMF01", "ATMCMF12"); $old = "c:/"; $new = "K:/ATM/"; print "Enter the month and day (ex:0605)\n"; $date = <stdin>; chomp($date); sub moving { print "Moving $_ to the K:/ATM \n"; move("$old$_","$new$_$date"); print "$_ has been moved to the K:/ATM\n"; print "---------------------------------------------\n"; } foreach (@files) { &moving; } print "All the ATM files have been renamed and move to the ATM folder\ +n"; $wait = <stdin>;

This is what i had at the beginning, at first it worked
because i was just moveing the files to another
folder on the c:, but when i start moveing
the files to a mapped drive all this started up so I tried
to rewrite it.
print "Enter the month and day (ex:0605)\n"; $date = <stdin>; chomp($date); move(c:/atmcaf00,K:/atm/atmcaf00$date); move(c:/atmcaf00,K:/atm/atmcaf01$date); move(c:/atmcaf00,K:/atm/atmcaf12$date); move(c:/atmcaf00,K:/atm/atmcmf01$date); move(c:/atmcaf00,K:/atm/atmcmf12$date); print "All the ATM files have been renamed and move to the ATM folder\ +n"; $wait = <stdin>;

Replies are listed 'Best First'.
Re: Moving files
by ikegami (Patriarch) on Jul 28, 2005 at 21:35 UTC

    I replaced move with print, and it worked for me. In other words, I don't think it's a Perl problem. Why don't you check what error move returned?

    if (move("$old$_","$new$_$date")) { print "$_ has been moved to the K:/ATM\n"; } else { print "Could not move $_: $!\n"; }
Re: Moving files
by shemp (Deacon) on Jul 28, 2005 at 21:25 UTC
    This is a result of your using $_ as a global variable. I cant see any good reason that you shouldn't pass the name of the file to be moved into your moving() function.

    I use the most powerful debugger available: print!
      Or just remove the sub entirely and move the code into the loop.

        This is what i had at the beginning, at first it worked
        because i was just moveing the files to another
        folder on the c:, but when i start moveing
        the files to a mapped drive all this started up so I tried
        to rewrite it.
        print "Enter the month and day (ex:0605)\n"; $date = <stdin>; chomp($date); move(c:/atmcaf00,K:/atm/atmcaf00$date); move(c:/atmcaf00,K:/atm/atmcaf01$date); move(c:/atmcaf00,K:/atm/atmcaf12$date); move(c:/atmcaf00,K:/atm/atmcmf01$date); move(c:/atmcaf00,K:/atm/atmcmf12$date); print "All the ATM files have been renamed and move to the ATM folder\ +n"; $wait = <stdin>;
        I tried that and it still did the same thing
        (copied the first file and skipped over the rest)
Re: Moving files
by NetWallah (Canon) on Jul 29, 2005 at 15:52 UTC
    While you are at it, you may want to clean up the hard-coded path in
    print "Moving $_ to the K:/ATM \n";
    and replace it with
    print "Moving $_ to $new\n";

         "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk