[pm-h] Recursive Directory Copy

G. Wade Johnson gwadej at anomaly.org
Sun Jun 8 07:02:53 PDT 2008


Hi Mike,

On Sat, 07 Jun 2008 20:54:26 -0600
Mike Flannigan <mikeflan at att.net> wrote:

> 
> Mike Flannigan wrote:
> > Do you guys know what is wrong here.  I'm trying to
> > copy a directory recursively.  I thought some combination
> > of these commands might work, but all give various errors
> > like "Invalid Argument".
> >
> > This is on Win32.
> >
> >
> > use strict;
> > use warnings;
> > use File::NCopy qw(copy);
> >
> > my $dir1 = "C:/Lame";
> >
> > my $dir2 = "C:/Copy2";
> >
> > copy \1,"$dir1","$dir2" or die "Copy failed: $!";
> > #copy "$dir1","$dir2" or die "Copy failed: $!";
> > #copy $dir1,$dir2 or die "Copy failed: $!";
> >
> >
> > #my $file = File::NCopy->new(recursive => 1);
> > #my $file = File::NCopy->new(u_chmod => \&my_chmod,f_check =>
> > \&my_fcheck); #$file->copy "$dir1","$dir2"  or die "Copy failed:
> > $!";
> >
> >
> > __END__
> >
> >   
> 
> Never mind.  I finally found one that works:
> 
> use strict;
> use warnings;
> use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove);
> 
> my $dir1 = "C:/Lame";
> 
> my $dir2 = "C:/Copy2";
> 
> dircopy($dir1,$dir2) or die "Copy failed: $!";
> 
> __END__
> 
> 
> This was much harder than it should be.

That's good to know.

Personally, I've rarely needed to copy a whole directory tree.

My normal problem is copying some subset of the tree (files and
directories that meet some criteria get copied and ignore the rest).
I've used one of the File::Find variants or walking the tree directly.

This looks like a useful module to know about.

G. Wade
-- 
Perl's grammar can not be reduced to BNF. The work of parsing perl is
distributed between yacc, the lexer, smoke and mirrors.
                                                    -- Chaim Frenkel


More information about the Houston mailing list