I have a Perl script that works on Windows XP.
It uses File::Copy's move
function to move a directory tree to another place on the same drive. The script fails (silently) on Windows 2008. Nothing moved, nothing deleted.
I am using ActiveState Perl 5.10.0 Build 1005 and the File::Copy that comes with it.
Anyone know of issues with ActiveState Perl on Windows 2008 that might cause this?
Example script:
use File::Copy;
print "Move AAA to ZZZ\n";
move("AAA", "ZZZ");
print "Done.\n";
From the documentation:
RETURN
All functions return 1 on success, 0 on failure. $! will be set if an error was encountered.
The example fails silently because nothing is checking what $! is on failure. Try this:
move($from, $to) || die "Failed to move files: $!";
If you don't want to have to check the return value, you can have autodie
do it for you.
Since move()
and copy()
return a zero to indicate an error, and that's what autodie
assumes, it's fairly straight forward.
use strict;
use warnings;
use File::Copy;
use autodie qw'copy move';
move("AAA", "ZZZ"); # no need to check for error, because of autodie
print "Done.\n";
Assuming that "AAA
" doesn't exist, here is the output ( on STDERR
).
Can't move('AAA', 'ZZZ'): No such file or directory at test.pl line 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With