in reply to Re: quickest way to find number of files in a directory?
in thread quickest way to find number of files in a directory?
++ to you. That's the way to go.
I like let handles close automatically on block exit (where feasible) and since this snippet fits naturally in a sub, I'd do this:
sub files_in_dir { my $dir = shift || '.'; opendir my $dh, $dir or croak "opendir '$dir' - $!"; grep { -f } readdir $dh; }
It produces the number of files if called in scalar context and the list of filenames if called in list context.
|
|---|