Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: count files in a directory

by j0se (Pilgrim)
on Oct 10, 2011 at 11:07 UTC ( #930586=note: print w/ replies, xml ) Need Help??

in reply to count files in a directory

To count the number of files in mydir you could use:

#!/usr/bin/perl use strict; use warnings; my $dirname = "/mydir"; opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n"; my $count; while ( (my $filename = readdir(DIR)) ) { next if $filename =~ /^\.{1,2}$/; # skip . and .. $count++; } closedir(DIR); print "$count files live in '$dirname'\n";

Update: a sample mail sending code.

Have a nice day, j

Comment on Re: count files in a directory
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930586]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2016-02-14 00:14 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (451 votes), past polls