Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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

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

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

As mentioned in the original post, some directories are not empty. How would this deal with those?
  • Comment on Re^2: How do I copy an empty directory?

Replies are listed 'Best First'.
Re^3: How do I copy an empty directory?
by hominid (Curate) on Oct 03, 2012 at 02:08 UTC
    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?"
      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996947]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-12-12 06:36 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (326 votes). Check out past polls.