Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by hominid (Curate)
on Oct 03, 2012 at 02:08 UTC ( #996958=note: print w/ replies, xml ) Need Help??


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

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?"


Comment on Re^3: How do I copy an empty directory?
Re^4: How do I copy an empty directory?
by Anonymous Monk on Oct 03, 2012 at 09:12 UTC
    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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-08-31 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls