Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Counting Certian Files in Windows

by batcater98 (Acolyte)
on Feb 13, 2007 at 19:35 UTC ( #599754=perlquestion: print w/replies, xml ) Need Help??
batcater98 has asked for the wisdom of the Perl Monks concerning the following question:

I have a need to count certian files in a given directory on a windows box. I have tried using Find and have even played around with Slurp, but can not get what I want. I am trying to count up all files that end with the extention of .dat and skip the rest and then output the count to a flat file. Suggestions? Thanks.

Replies are listed 'Best First'.
Re: Counting Certian Files in Windows
by bart (Canon) on Feb 13, 2007 at 19:51 UTC
    my $count = 0; $count++ foreach glob "$dir/*.dat";
    Will that do?
Re: Counting Certian Files in Windows
by ptum (Priest) on Feb 13, 2007 at 19:51 UTC

    What have you tried so far? You may want to try File::Find as a starting point, although there are several ways that are simpler than this.

Re: Counting Certian Files in Windows
by swampyankee (Parson) on Feb 14, 2007 at 04:56 UTC

    The ideas will come down to getting a list of all the files with the extension ".dat", using glob and counting the elements in the returned array (see scalar), or you could open the directory of interest, and read the names of the files, and increment a counter when the file's name ends in .dat.

    I'd use glob and count the number of elements in the returned list; chances are that there won't be more than a few hundred files with names ending in /\.dat$/i, so memory use won't be a concern.

    Or you could install cygwin and do this:

    ls *.dat | wc


    Insisting on perfect safety is for people who don't have the balls to live in the real world.

    —Mary Shafer, NASA Dryden Flight Research Center

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://599754]
Approved by bart
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2016-10-22 06:36 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (292 votes). Check out past polls.