in reply to Difficulties in copying directories from one network drive to another.

My suggestion would be to use File::Copy and File::Spec.

use File::Spec; use File::Copy; $folder1=File::Spec->catdir('//computerA','share','folder'); $folder2=File::Spec->catdir('//diffcomputer','share','new folder'); copy "$folder1/file.txt", "$folder2/new_file.txt" or die "Cannot copy +file.txt from $folder1 to $folder2. $!";

In that snippet, note the direction of the slashes for the computer name. It might seem backwards but it works. Also, using single quotes instead of double quotes means that the slashes won't get interpolated. And this does work, we do it all the time, every day in fact. All our scripts use UNC or absolute pathnames (Windows or Unix). What you may be running into is a problem with the space in the "other folder" name. Just a hunch, it causes us problems with some things unless we specially wrap double quotes around it to get it to work right. Hope that helps.

update: My mistake, I misread. I thought you were talking about files, not directories.

  • Comment on Re: Difficulties in copying directories from one network drive to another.
  • Download Code

Replies are listed 'Best First'.
Re^2: Difficulties in copying directories from one network drive to another.
by doowah2004 (Monk) on Sep 16, 2004 at 20:23 UTC
    I gave it a try...still no go. I then tried to copy a file with it and not a directory...no good either. If I use:
    sub copyFile { my $source=shift(@_); my $dest=shift(@_); my $moo=1; open(FA,$source); open(F,">$dest"); binmode(F); binmode(FA); while(($moo=read(FA,$buff,4096))>0){ print F $buff; } close(FA);close(F); }

    Taken from CopyDocs, I can copy a file no prob from one network computer to the other. But I need to transfer a directory. Hmmm...I may have to breakdown and write a subroutine that uses the above recursively and create the directories.

    Cameron