in reply to Re: cleaning up old libs and @INC
in thread cleaning up old libs and @INC

4. I was left with a lot of empty directories. I ran find with rmdir a couple of times do get rid of them.
A "couple of times"??

A pure perl solution is to use File::Find and use finddepth instead of find. That way it'll kill the deepest lieing empty directories first.

Oh, and rmdir will not delete a directory if it's not empty.

So you can easily recursively delete empty directories in Perl using:

use File::Find qw(finddepth); finddepth sub { -d and rmdir $_ and printf STDERR "rmdir: %s\n", $File +::Find::name }, @dirs;
which can probably easily be converted to a one-liner — and shortened if you don't like the verbosity:
finddepth sub { -d and rmdir $_ }, @dirs;
I haven't tried running rmdir on a plain file. Probably it's safe.

Replies are listed 'Best First'.
Re^3: cleaning up old libs and @INC
by daxim (Curate) on Jul 16, 2007 at 18:55 UTC
    A "couple of times"??
    I felt particularly lazy there. Writing even a perl one-liner would have required more effort and documentation reading than it's worth. Running rmdir each time prunes the most nested empty dir, and I knew they would not nest deeper than 5 or 6. Much quicker.
    Oh, and rmdir will not delete a directory if it's not empty.
    I knew that. That was the point of using it.