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

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



hi,

I'm trying to copy the contents of a folder preserving the structure. In my
first attempt I asumed that if I copied a folder the contents would be
copied aswell, but no, nothing got copied at all so I still can't figure
out if I was on the right track here...

#! perl -w

use strict;

use File::Copy;
use File::Basename;

my $target_folder = "MacOS:backa_det:";


unless (-e $target_folder){
    mkdir($target_folder, 0755) || die "couldn't create $target_folder $!\n";
}

foreach (@ARGV){
   my ($file, $path) = fileparse($_);
   copy("$file:", "$target_folder$file:");
   print "$file\n";
}


Then I thought I'd try with File::Find and traverse the folder and copy
each file. But when I did this it only copies the "files" at the top level
of the folder dropped on the script, however it traverses all the way down
in the print statement, I'm kind of lost here.

To me it seems as if folders are invisible to copy(), but I guess that's
quite far from the truth;).


#! perl -w

use strict;

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


my $target_folder = "MacOS:backa_det";


unless(-e $target_folder) {
    mkdir($target_folder, 0755) || die "kunde inte skapa $target_folder $!\n";
}


foreach (@ARGV){
    find(\&copy_them, $_);
    print "$_\n";
}


sub copy_them {
    my $file = $File::Find::name;
    my ($name, $path) = fileparse($file);

    copy("$name", "$target_folder$path$name");
    print "$path$name\n";

# Figuring that it would be alright to use "$target_folder$path$name" here
# since I'm copying from top to bottom level, right? hence the parent dirs
would
# always exist.

}

I'd be grateful if someone wants to point out where I'm going wrong here!

Thanks,
/Martin



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