http://qs1969.pair.com?node_id=520799


in reply to Find Empty directories and removing it

Try using the opendir and readdir functions along with a file test. Something like:

opendir (DIR, ".") or die "Cannot open the current directory: $!"; my @files = grep {$_ ne '.' and $_ ne '..'} readdir DIR; close (DIR) or die "Cannot close the current directory: $!"; foreach my $file (@files) { if (-d $file) { opendir (SUBDIR, "$file") or die "Cannot open the sub director +y: $!; my @subfiles = grep {$_ ne '.' and $_ ne '..'} readdir DIR; closedir(SUBDIR) or die "Cannot close the sub directory: $!"; unless (@subfiles) { unlink("$file"); } } }

I have not actually tried this to be sure it works. Furthermore, it only deletes empty directories in the current directory. You would need to convert it into a recursive subroutine if you wanted to mine further into the directory tree.