in reply to (golf) Recursively delete empty directories from a tree

This one doesn't count directories, and might break if the directories have funny characters in them. It doesn't use much Perl either, but it's waaaaaaaaaaaaaay shorter than yours:
`find @ARGV -type d -depth | xargs rmdir`;
If you modify it to:
`find @ARGV -type d -depth | xargs rmdir 2>&1 | wc -l`;
it'll tell you the amount of directories not removed.

Abigail

Replies are listed 'Best First'.
Re: Re: (golf) Recursively delete empty directories from a tree
by Anonymous Monk on Feb 19, 2004 at 05:23 UTC
    if you have the GNU text utilities most of them have a '-0' type option to seperate filenames with nulls.
    find . -type d -depth -print0 | xargs -0 prog
    which helps alot with the funky character problem. also there's the '-exec' option to find.
    find . -type d -depth -exec rmdir -- {} \;
    which (i think) bypasses the shell so funky characters are no problem. the '--' option is handy to turn off further argument processing so a directory like '-r' isn't taken as a flag.