Recursive copy

Discussion in 'Perl' started by gusmeister, Aug 19, 2003.

  1. gusmeister

    gusmeister Guest

    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).
     
    gusmeister, Aug 19, 2003
    #1
    1. Advertising

  2. gusmeister

    Phil Crow Guest

    "gusmeister" <> wrote in message news:<4og0b.661$>...
    > 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');
     
    Phil Crow, Aug 20, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    2
    Views:
    1,235
  2. Replies:
    26
    Views:
    2,120
    Roland Pibinger
    Sep 1, 2006
  3. n00m
    Replies:
    12
    Views:
    1,116
  4. vamsi
    Replies:
    21
    Views:
    2,081
    Keith Thompson
    Mar 9, 2009
  5. qewrty
    Replies:
    2
    Views:
    118
    qewrty
    Feb 16, 2005
Loading...

Share This Page