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

Dear Monks

Any suggestions how I can move multiple files from A to B. I tried:
#! /usr/bin/perl use File::Copy ; move ("a*","tmp/" ) ;
Thnx Luca

Replies are listed 'Best First'.
Re: moving multiple files
by svenXY (Deacon) on Jan 16, 2006 at 13:32 UTC
Re: moving multiple files
by prasadbabu (Prior) on Jan 16, 2006 at 12:10 UTC

    You can move multiple files from one location to another location by following way.

    use File::Copy; @files = ("file1", "file2"); move ("c:\/A\/$_", "c:\/B\/$_") for @files;

    Prasad

Re: moving multiple files
by blazar (Canon) on Jan 16, 2006 at 13:05 UTC

    You either want to use a shell for a shell job or use Perl's flow control structures to combine simple statements into more complex ones:

    move $_, "tmp/$_" for glob 'a*';

    is not that hard(er) to type (than your hypothetical code). Be sure to add the necessary checks!

Re: moving multiple files
by spiritway (Vicar) on Jan 17, 2006 at 06:51 UTC
    #!/usr/bin/perl -w use strict; use warnings; use File::Copy; my $olddir= "./Old"; my $newdir="./New"; opendir DH, $olddir; while(my $file = readdir DH) { move "$olddir/$file" , "$newdir/$file"; } closedir DH;
      blazar@q ~/test $ mkdir Old blazar@q ~/test $ touch Old/foo blazar@q ~/test $ touch Old/bar blazar@q ~/test $ ./spiritway.pl blazar@q ~/test $ ls -R .: Old spiritway.pl ./Old: bar foo blazar@q ~/test $ mkdir New blazar@q ~/test $ ./spiritway.pl './Old/..' and './New/..' are identical (not copied) at ./spiritway.pl + line 11 blazar@q ~/test $ ls -R .: New Old spiritway.pl ./New: ./Old: bar foo