in reply to Re: Re: how to get total numbers of files in a directory?
in thread how to get total numbers of files in a directory?

That has the disadvantage of potentially using a lot of memory if there are many files in the directory (the globbing solutions, and solutions that use readdir in list context all suffer from this).

I would use something like:

my $cnt = 0; local $_; chdir "/home/a" or die "chdir: $!"; opendir my $dh => "." or die "opendir: $!"; -f && /\.txt$/ && $cnt ++ while defined ($_ = readdir $dh); closedir $dh;

Abigail

Replies are listed 'Best First'.
Re: Re: how to get total numbers of files in a directory?
by Murcia (Monk) on Dec 10, 2003 at 13:19 UTC
    or a simple shell script? find . -maxdepth 1 -name '*.*' | wc -l