As mentioned in the original post, some directories are not empty. How would this deal with those? | [reply] [Watch: Dir/Any] |
The question, smartass, was
"How can I move the empty directory named "empty" at the end of the path to c:\temp for example to make c:\temp\empty?"
| [reply] [Watch: Dir/Any] |
Well, what that guy said, could work, if the directory is not empty, then rmdir won't remove it, so
#!/usr/bin/perl --
use Path::Class::Rule;
my $source = dir( 'x:\this\directory\name\is\empty' );
my $newdir = $dd->basename;
my $destination = dir( 'C:\temp' );
if( rmdir $dd ){
my $newdir = dir( $destination, $newdir );
if( mkdir $newdir ){
} else {
warn "Couldn't mkdir $newdir : $! $^E \n restoring $source ";
mkdir $source or die "FAILED $! $^E";
}
} else {
die "Couldn't rmdir $dd : $! $^E";
}
Naturally this doesn't try to preserve permissions or anything like that
File::Copy::move should also work with empty dirs
| [reply] [Watch: Dir/Any] [d/l] |