use strict; use warnings; my $error; if (!dirEmpty($ARGV[0], $error)) { print $error ? "$error\n" : "Directory contains files.\n"; } else { print "Directory is empty.\n"; } sub dirEmpty { if (!-e $_[0]) { $_[1] = 'Directory does not exist.'; return; } if (!-d $_[0]) { $_[1] = 'Path does not reference a directory.'; return; } if (!opendir(DIR, $_[0])) { $_[1] = 'Could not open directory.'; return; } while ($_ = readdir(DIR)) { next if m/^\.\.?$/; return; } return 1; }
In reply to Re: How to tell if a Directory is Empty
by TJPride
in thread How to tell if a Directory is Empty
by ishootperls
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |