in reply to Re^2: What is the best way to move a directory?
in thread What is the best way to move a directory?
Thanks! The fact that File::Copy is one of the standard (already installed) Perl modules is a plus.
---------------------------- use File::Copy; my $source_dir = '/home/my/this_dir'; my $destination_dir = '/usr/local/elsewhere/this_dir'; move("$source_dir", "$destination_dir"); ----------------------------
And I think this
----------------------------
use File::Copy;
use Carp qw(croak);
move_reliable("$source_dir", "$destination_dir");
sub move_reliable {
my ( $source, $destination ) = @_;
my $source_size = (-s $source) || 0;
move( $source, $destination )
|| croak("move_reliable($source, $destination) failed: $!");
my $destination_size = (-s $destination) || 0;
croak(
"move_reliable($source, $destination) failed copied $destination_size bytes out of $source_size"
)
if ( $source_size != $destination_size );
1;
}
----------------------------
from Leon Brocard's File::Copy::Reliable is also nice.
|
|---|