I needed to find a quick way to find out if a directory was empty or not. After hours (30 minutes) of google searching, I didnt find anything worth using. So I wrote my own code, which is what I should have done if I wasnt trying to find the easy way out. Enjoy! Feel free to chime in.
$i=0; opendir(DIR, "$someDir") or die "Cant open $someDir: $!\n"; @files = readdir(DIR); foreach $file(@files) { unless ($file =~ /^[.][.]?\z/) { $i++; } } if ($i != 0) { print "There is Stuff in here!"; } else { print "This Dir is Empty!"; } closedir(DIR);
In reply to How to tell if a Directory is Empty by ishootperls
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |