Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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


Comment on Re: Copying a directory recursively
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-10-31 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (215 votes), past polls