[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] File::, trying to mirror a folder and not succeeding;)



At 21.02 -0500 2000.01.05, Paul Schinder wrote:
>You should probably go to CPAN and try File::NCopy if you really want
>to do this entirely in Perl.  I'm not sure it works under MacPerl,
>though, but I think it does recursive copies, which is what you seem
>to want.  You'll probably have an easier time fixing it if it doesn't
>work than you will to discover all the pitfalls for yourself.
>
>But in this case there's a better way.  Open Shuck, look under Go ->
>Macintosh Toolbox Modules -> More File Routines.  There's a
>
>	FSpDirectoryCopy SRCSPEC, DSTSPEC, PREFLIGHT, [COPYERRHANDLER]
>
>
>If all you want is something that works under MacPerl, this is likely
>the best way to do it.  (I still don't know what PREFLIGHT is,
>though.)

Incidentally, a basic program to do this with File::Find is not hard.  It
may not do everything you want.  Maybe it does.  I dunno.  :)

#!perl -w
use File::Copy;
use File::Find;
use File::Path;
my $dir1 = "Bourque:Desktop Folder:xta:";
my $dir2 = "Bourque:Desktop Folder:xtb:";

find(sub {
    my $file = $File::Find::name;
    (my $nfile = $file) =~ s/^\Q$dir1/$dir2/;

    if (-l $file) {
        symlink readlink $file, $nfile;
    } elsif (-d $file) {
        mkpath($nfile) or die "Can't mkpath $nfile: $!";
    } elsif (-f _) {
        copy($file, $nfile) or die "Can't copy $file, $nfile: $!";
    }
}, $dir1);

__END__

But of course, in MacPerl the FSpDirectoryCopy() function is essentially
simpler.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org