http://www.perlmonks.org?node_id=335314


in reply to Copying a directory recursively

I raced off to program a solution in Perl, trying to beat everyone else. The result follows, although it doesn't handle binary and Only now I've noticed that you wanted recursion, but that is fairly easy to add on.
#!usr/bin/perl -W # pure Perl directory copying script use File::Find; $from = $ARGV[0]; # from should be full path $to = $ARGV[1]; # to should have / at the end mkdir( $to ) || die "cant mkdir $to: $!"; find( \&copyroutine, $from ); sub copyroutine { if( $_ eq '.' || $_ eq '..' ){ return 1 } print "got $_\n"; open( FROM, $_ ) || die "cant open $_: $!"; open( TO, "> $to$_" ) || die "cant make $to$_ : $!"; while( $line = <FROM> ) { print TO $line; } close TO; close FROM; }

I know just how much everyone likes to perfect solutions, and add alternate ones - so I leave it to others to implement recursion and binary handling. The above code works with a flat directory on my trusty 333Mhz windows box.

The guy with the awful signature