Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-12-27 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls