Instead of scrolling through another half-dozen Perl modules looking for the one that did what I wanted, I took a hybrid approach and called DOS to use the move command. The DOS movement has its own characteristics. For example, if you copy c: \ temp \ AAA to c: \ temp \ BBB and BBB already exists, you get c: \ temp \ BBB \ AAA. But if the BBB does not exist yet, you get c: \ temp \ BBB, without AAA under it. To avoid this, I first create a BBB (if it does not exist) and then removes it. This leads to the creation of all directories before the BBB, if they are missing.
Here is my code:
sub move($$) { my ($source, $target) = @_; if (! -d $source) { print " ERROR: Source directory does not exist: $source. Not copying to $target.\n"; } elsif (-d $target) { print " ERROR: Target directory already exists: $target. Not copying from $source.\n"; } else { $source =~ s|/|\\|g; $target =~ s|/|\\|g; my $results = `if not exist "$target" mkdir "$target" & rmdir "$target" & move /Y "$source" "$target"`; print " Results of move \"$source\" \"$target\":\n $results\n"; } }
source share