in reply to Empty directory
By the very act of reading something other than . or .., we imply the existence of files in that directory. If there are no files, we fall through the loop and return 0.sub AreThereFiles { opendir DIR, "/path/to/nowhere" or die "That will linger: $!\n"; while ( $foo = readir DIR ) { chomp $foo; next if ( $foo =~ s/^\.\.?$/ ); closedir DIR; return 1; } closedir DIR; return 0; }
This method will be a little slower than slurping it all into an array. But, if your directories look like some of my user's it may not actually be all that slower and the memory savings will be worth it.
Yes, the closedir calls are likely redundant but I have been bitten a few too many times while recursing directories and I tend to include them from sheer paranoia.
Mik
Mik Firestone ( perlus bigotus maximus )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Empty directory
by chromatic (Archbishop) on May 16, 2000 at 04:19 UTC | |
by turnstep (Parson) on May 16, 2000 at 20:18 UTC | |
|
RE: RE: Empty directory
by mdillon (Priest) on May 15, 2000 at 22:19 UTC |