in reply to Empty directory

I'd try something like this...
sub files_in_dir{ my $dir=shift; opendir D,$dir; my @f=readdir D; closedir D; if(scalar(@f)<=2){ # no files in directory return 0; }else{ # at least 1 file in directory return 1; } }

Replies are listed 'Best First'.
RE: Re: Empty directory
by turnstep (Parson) on May 16, 2000 at 20:15 UTC

    You really should check the return status of the opendir and not let the script go any further if it fails.

    How about:

    sub numfiles { opendir D, shift or die "Ugh. $!\n"; grep !/^\.{1,2}$/, readdir D; }
RE: Re: Empty directory
by merlyn (Sage) on May 15, 2000 at 21:25 UTC
    Why the useless use of scalar? Voodoo? What are you expecting it to do?