in reply to Re: Moving directories
in thread Moving directories

<KBD>> move("dir 1", "dir2");</KBD>

Up to now I've written only wimpy little scripts (aside from that replacement for getopts :)
and have had no occasion to use file::copy...until a couple of minutes ago.

It worked as advertised given the suggestion quoted above (same drive). It failed
("Permission denied") if the destination was a not-yet-created directory on another drive.

It didn't error out--but still didn't move anything--when the destination directory,
on another drive, existed at the time the command was given.

The friend gave few details in his e-mail but I'm guessing he wants to move entire trees
from one drive to another.

Replies are listed 'Best First'.
RE: RE: Re: Moving directories
by davorg (Chancellor) on Jun 27, 2000 at 12:01 UTC

    If you want to move whole trees then you could do something using File::Find. Something like this perhaps (untested)

    use File::Find; use File::Copy; my $src = '/some/directory/'; my $tgt = '/some/other/directory/'; find($src, \&move_it); sub move_it { if (-d $File::Find::name) { $File::Find::name =~ s/$src/$tgt; mkdir $File::Find::name, 0777 unless -d $File::Find::name; } else { my $new = $File::Find::name; $new =~ s/$src/$tgt; copy($File::Find::name, $new); } }
    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000
    <http://www.yapc.org/Europe/>