in reply to RE: Empty directory
in thread Empty directory

Let's make that compile :) and not return true if there are only directories:
sub AreThereFiles { opendir DIR, "/path/to/nowhere" or die "That will linger: $!\n"; while (my $foo = readir DIR ) { chomp $foo; next if ( $foo =~ m/^\.\.?$/ ); next unless (-f $foo); closedir DIR; return 1; } closedir DIR; return 0; }
I put the -X test in there because the original poster mentioned looking for files. If the existence of a sub-directory is appropriate, you can leave it out.

Replies are listed 'Best First'.
RE: RE: RE: Empty directory
by turnstep (Parson) on May 16, 2000 at 20:18 UTC
    Some further nitpicking:
    • It's still readdir not readir :)
    • The chomp is not needed
    • Using $_ instead of my $foo would make things cleaner, i.e.
      next if /^\.\.?$/ or ! -f;