Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Recursive copy

Reply
Thread Tools

Recursive copy

 
 
gusmeister
Guest
Posts: n/a
 
      08-19-2003
Is there a Perl mod that has a recursive file copy function (similar to
`cp -r` in Unix or `xcopy` in Windows)? File:ath does have a recursive
file deletion function (rmtree) but no recursive copy function (e.g.
cptree).


 
Reply With Quote
 
 
 
 
Phil Crow
Guest
Posts: n/a
 
      08-20-2003
"gusmeister" <(E-Mail Removed)> wrote in message news:<4og0b.661$(E-Mail Removed)>. ..
> Is there a Perl mod that has a recursive file copy function (similar to
> `cp -r` in Unix or `xcopy` in Windows)? File:ath does have a recursive
> file deletion function (rmtree) but no recursive copy function (e.g.
> cptree).


You could combine File::Find which recursively descends directories
and File::Copy which copies files. I can't be sure the following code
will work without knowing a bit more about how you want the
destination to look, but it might go something like this:

use File::Find;
use File::Copy;

sub visit {
my $file = $File::Find::name;
my $base = $file;
$base =~ s!/base/path/to/remove/!!;
copy($file, "/new/path/$base");
}

find({ wanted => \&visit, no_chdir => 1 }, '/base/path/to/remove');
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive functions Vs Non-recursive functions - performance aspect vamsi C Programming 21 03-09-2009 10:53 PM
Two recursive calls inside of a recursive function n00m C++ 12 03-13-2008 03:18 PM
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
How to overwrite while doing recursive copy qewrty Ruby 2 02-16-2005 10:42 PM



Advertisments