Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: count files in a directory

by reisinge (Friar)
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

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 romping around the Monastery: (4)
As of 2016-10-22 23:55 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (299 votes). Check out past polls.