Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Counting Certian Files in Windows

by batcater98 (Acolyte)
on Feb 13, 2007 at 19:35 UTC ( [id://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

    emc

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found