467,858 Members | 1,706 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

Recursive copy

Is there a Perl mod that has a recursive file copy function (similar to
`cp -r` in Unix or `xcopy` in Windows)? File::Path does have a recursive
file deletion function (rmtree) but no recursive copy function (e.g.
cptree).
Jul 19 '05 #1
  • viewed: 6877
Share:
1 Reply
"gusmeister" <gu****************@sympatico.ca> wrote in message news:<4o******************@news20.bellglobal.com>. ..
Is there a Perl mod that has a recursive file copy function (similar to
`cp -r` in Unix or `xcopy` in Windows)? File::Path 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');
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Steve Goldman | last post: by
7 posts views Thread by bearophileHUGS | last post: by
3 posts views Thread by Bernie | last post: by
7 posts views Thread by Jon Slaughter | last post: by
64 posts views Thread by dmattis | last post: by
5 posts views Thread by Seong-Kook Shin | last post: by
9 posts views Thread by Csaba Gabor | last post: by
7 posts views Thread by pereges | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.