Not having a plethora of systems to work with, I couldn't say how portable that is, but given the ubiquity of File::Spec it should be relatively reliable. However, I'd say in this case it'd probably be simpler just to have a switch-esque statement to call the appropriate system copying tool per system to get reliable and consistent recursive copying.use strict; use warnings; use File::Basename 'basename'; use File::Find::Rule 'find'; use File::Path 'mkpath'; use File::Copy 'copy'; use File::Spec::Functions qw/ splitdir catdir splitpath catfile /; $::PROG = basename $0; my($orig, $new) = @ARGV; die "Usage: $::PROG SRC DEST\n" unless defined $new and defined $orig; my $iter = find start => $orig; while(my $ent = $iter->match) { if(-d $ent) { my $mode = ( stat $ent )[2]; my @src = splitdir $ent; my $dest = catdir $new => @src; mkpath $dest => 0, $mode or die "$::PROG: Couldn't create '$ent': $!"; } else { my @src = splitpath $ent; my $dest = catfile $new => @src; copy $ent => $dest or die "$::PROG: Couldn't copy '$ent': $!"; } }
_________
broquaint
In reply to Re: Copying a directory recursively
by broquaint
in thread Copying a directory recursively
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |