in reply to How to tell if a Directory is Empty
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to tell if a Directory is Empty
by Anonymous Monk on Nov 27, 2011 at 08:28 UTC | |
by Anonymous Monk on Nov 27, 2011 at 10:05 UTC | |
by MarxBro (Initiate) on Feb 20, 2012 at 23:05 UTC | |
by afoken (Chancellor) on Feb 22, 2012 at 18:52 UTC | |
by MarxBro (Initiate) on Feb 27, 2012 at 05:42 UTC |