in reply to writtings files to a new folder
use File::Copy; our $VERBOSE = 1; # turn this off if you don't need the verbose messag +es for my $file (@files) { if (-f "old/$file") { print "old/$file -> new/$file\n" if $VERBOSE; move("old/$file", "new/.") or die "move: old/$file: $!"; } }
Note that if this encounters an error, it'll stop in the middle. Maybe in your application it's more right to push the erring filename to a @failed array and then print them all, retry, whatever. I don't know; it's just something to think about.
Also, I've assumed "/" is a correct filepath separator and in most cases it is, but if you want to write really portable code you'll want to look into File::Spec.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: writtings files to a new folder
by rinceWind (Monsignor) on Jan 24, 2007 at 09:36 UTC |