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

And some examples of usage

File::Find::Rule

use File::Find::Rule; my $cnt = find( file => name => "*.txt", maxdepth => 1, in => "/home/a" );
glob - Update: fixed bug as noted by sauoq below (it was originally going to be @{ [ glob "*.txt" ] }, that'll teach me for posting in a hurry :)
my $cnt = () = glob "/home/a/*.txt";
opendir, readdir + grep
opendir( my $d, "/home/a" ) or die "ack: $!"; my $cnt = grep { -f and /\.txt$/ } readdir $d;
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Re: how to get total numbers of files in a directory?
by sauoq (Abbot) on Dec 09, 2003 at 21:07 UTC
    my $cnt = glob "/home/a/*.txt";

    Unfortunately, no. It would be more intuitive that way, but the real behavior of that is to set $cnt to the first filename in the list of exansions.

    $ touch {a,b,c}.txt; perl -le 'my $c = glob "*.txt"; print $c' a.txt
    The clunky fix is to force list context...
    $ touch {a,b,c}.txt; perl -le 'my $c =()= glob "*.txt"; print $c' 3

    -sauoq
    "My two cents aren't worth a dime.";