Gossamer Forum
Home : General : Perl Programming :

Counting number of files

Quote Reply
Counting number of files
i used to know this, but i don't remember anymore. Anyway, how would i count, lets say, the number of files in a folder that end with .id.

Quote Reply
Re: Counting number of files In reply to
Hi,

Try...

Code:
my $dir = "/path/to/dir";
my @count = ();
opendir(DIR, $dir) || die "Can't open $dir : $!";
@count = grep { /\.id$/i } readdir(DIR);
closedir(DIR);
Code:
my $total = scalar @count;
Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Counting number of files In reply to
Hey Paul,
i'm [glad] you are around this forum. That did exactly what i wanted. I'm not too familiar with grep. Anyway, thanks alot.

Quote Reply
Re: Counting number of files In reply to
My pleasure - it saved me from a university assignment for a few minutes Smile

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/