Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Copying a directory recursively

by bl0rf (Pilgrim)
on Mar 10, 2004 at 02:05 UTC ( #335314=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335314]
[1nickt]: erix you should try flat-file DB with linked DBM index yadayada. Might be faster!

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-12-12 01:27 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (321 votes). Check out past polls.