http://qs321.pair.com?node_id=608502


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?

Are we talking quick, as in coding/thinking time? ` ls -a1 | wc -l`
  • Comment on Re^2: quickest way to find number of files in a directory?

Replies are listed 'Best First'.
Re^3: quickest way to find number of files in a directory?
by izut (Chaplain) on Apr 05, 2007 at 19:43 UTC

    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