Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: quickest way to find number of files in a directory?

by jdporter (Canon)
on Mar 27, 2007 at 20:05 UTC ( #606862=note: print w/replies, xml ) Need Help??


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.

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-11-29 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?