http://www.perlmonks.org?node_id=606814


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?

Nit-picking: the dot files (like ".bashrc") are not counted when using the glob.

Replies are listed 'Best First'.
Re^3: quickest way to find number of files in a directory?
by Anonymous Monk on Mar 27, 2007 at 20:22 UTC
    That depends on your shells. At least under bash, you can use glob() to grab dot files, for example:
      print "$_\n" for grep{ -f } glob(".*");
    
    Or probably if you want to grab both dot and non-dot files:
      print "$_\n" for grep{ -f } glob("{*,}.*");
    
    Regards,
    Xicheng

      Nope. It does not depend on your shell. At least not if you're using Perl 5.6 or later, because glob is implemented via the standard File::Glob extension and does not rely on shell anymore.

      The standard behavior of <*> or glob('*') is to not consider the dot files.

        In the example given, glob is not used with '*'.
Re^3: quickest way to find number of files in a directory?
by Anonymous Monk on Jul 24, 2012 at 15:38 UTC
    is it efficient with more than 100 000 files in the directory ? if I well understand the code, each inode is loaded in memory... so do you know another mean to get this count, without need of a huge memory ?