Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: How do I copy an empty directory?

by Anonymous Monk
on Oct 03, 2012 at 09:12 UTC ( #997018=note: print w/ replies, xml ) Need Help??


in reply to Re^3: How do I copy an empty directory?
in thread How do I copy an empty directory?

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


Comment on Re^4: How do I copy an empty directory?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-27 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls