Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by izut (Chaplain)
on Mar 28, 2007 at 00:16 UTC ( #606887=note: print w/replies, xml ) Need Help??


in reply to quickest way to find number of files in a directory?

Depending on the amount of the files you're talking about, maybe File::Find::Rule fit your needs:

use strict; use warnings; use File::Find::Rule; my @files = File::Find::Rule->file()->in('/my/path'); print scalar @files, $/;

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^2: quickest way to find number of files in a directory?
by Anonymous Monk on Apr 05, 2007 at 15:38 UTC
    Are we talking quick, as in coding/thinking time?
    ` ls -a1 | wc -l`
    Well -2 entries for . and ..
Re^2: quickest way to find number of files in a directory?
by Anonymous Monk on Apr 05, 2007 at 15:35 UTC
    Are we talking quick, as in coding/thinking time? ` ls -a1 | wc -l`

      Well, you could also do `find /tmp -type f | wc -l`, but I think that backticks are evil. Ah, and we also could free our minds from Perl and write some nasty bash script code :-P.

      Igor 'izut' Sutton
      your code, your rules.

        Hi; What I would like is a Perl native recursive descent file counter, not just the files in one directory, but nested directories as well. I would like the equivalent of: "find $dir | wc -l" # I want all (files, dirs and symlinks) I tried File::Find where my wanted was "sub {$file_count++}", but I get a warning "variable will not stay shared", but it seems to be the correct number. Is there a better way? Native Perl (or CPAN, but I don't see this on CPAN)... Thanks, Ken Wolcott

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-11-28 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?