# This script will copy the whole source directory tree # to the destination. Be carefull that if the root target # ( destination ) directory does not exists then it will be # created. This script will work only on Windows platforms, # but with some small changes will work on unix as well. # The destination files will be over writen if they exist. # Xxxxxx Xxxxxx # xxxx@xxxxxxxx.xxxxx.xxx my $source_directory = 'f:/temp' ; my $target_directory = 'c:/temp' ; &xcopy($source_directory,$target_directory); ############# xcopy subroutine ############# use IO::Dir; sub xcopy { my ($src,$dst) = @_; unless (@_ == 2) { die('Usage: xcopy($src, $dst)') } my $dh = IO::Dir->new; if (-e $dst) { die "File $dst exists but is not a directory" unless -d _; } else { mkdir $dst or die "Couldn't create dir $dst: $!"; } opendir ($dh,$src) || die "Can't open dir $src: $!\n"; while (my $file = readdir $dh) { next if $file eq '.' || $file eq '..'; my ($src_file, $dst_file) = ("$src/$file", "$dst/$file"); if (-d $src_file) { xcopy($src_file, $dst_file); } elsif (! -e $dst_file) { print "coping $file to $target_node\n"; tr{/}{\\} for $src_file, $dst_file; system("$ENV{ComSpec} /c copy /b $src_file $dst_file"); } } }