Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, Does anyone know a simple function to search a directory for empty folders? Thank you.

Replies are listed 'Best First'.
Re: Empty Folders
by apl (Monsignor) on Jun 02, 2008 at 19:13 UTC
Re: Empty Folders
by kyle (Abbot) on Jun 02, 2008 at 19:14 UTC

    If you don't mind going to the shell...

    my @empty_directories = `find $dir -type d -empty -print`;

    If you do mind going to the shell, you could use File::Find with a wanted function that checks directories for emptiness (opendir, readdir, see what's there).

Re: Empty Folders
by linuxer (Curate) on Jun 02, 2008 at 19:14 UTC

    Interesting question; I was lazy and asked google and found an interesting answer:

    DeleteEmptyDirectories

    hth

    update; don't know why my mind thought you wanted to delete the empty ones ;)

Re: Empty Folders
by smokemachine (Hermit) on Jun 03, 2008 at 17:19 UTC
    perl -e 'sub emptyFolders{my$dir=shift; $dir .="/" if $dir; my@dirs; w +hile(<$dir*>){next unless -d; push @dirs, $_ if scalar (my@a=<$_/*>)} +return @dirs} print $_, $/ for emptyFolders'