in reply to Move and rename files

my $dir_1 = '/some/dir'; my $dir_2 = '/other/dir'; opendir DIR, $dir_1 or die "Cannot open '$dir_1' $!"; while ( my $file = readdir DIR ) { rename "$dir_1/$file", "$dir_2/${file}_processed" or die "Cannot m +ove '$dir_1/$file' $!"; }

Replies are listed 'Best First'.
Re^2: Move and rename files
by Chon-Ji (Novice) on Jun 29, 2006 at 03:16 UTC
    so there's no way to do it withouta loop? I was thinking mv command could do the job...
      What's wrong with a loop? Even a mv command would have to do some looping internally.

      You could of course write a mv subroutine, hide it away in a module, then use the module and call the mv sub/method. The users would not see the loop, but internally it will still be doing just that.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Perl doesn't have a mv command.