So the sub directories in DirA will be combined with like-named sub
directories in DirB and they will move up a level in the hierarchy.
Untested:
Why not use File::Copy::Recursive's dircopy() it has been tested and its simpler (to develop code and maintain it later or if you inherit the job) :)
use strict; use warnings; use File::Copy::Recursive 'dircopy';
my $target = shift @ARGV;
dircopy($_,$target) or warn "$target -> $_ : $!" for @ARGV;
now you can
./myrsync.pl target DirA DirB DirC /etc
or just rsync like was also mentioned
use warnings; use strict; use File::Find; use File::Copy; use File::Path; use File::Spec;
my @dirs = qw( DirA DirB );
for my $dir ( @dirs ) { find( sub { my @paths = File::Spec->splitdir( $File::Find::dir ); for my $i ( 0 .. $#paths ) { if ( $path[$i] eq $dir ) { splice @paths, $i, 1; last; } } my $new_dir = File::Spec->catdir( @paths ); mkpath( $new_dir ) unless -d $newdir; if ( -e "$newdir/$_" ) { warn "$newdir/$_ already exists, cannot copy!\n"; } else { copy( $_, "$newdir/$_" ); } }, $dir ); }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>