joaase has asked for the wisdom of the Perl Monks concerning the following question:
I'm new in perl trying to create a simple script. my goal is to create script to use for Nagios. trying to create a script that is count file in a specifict directory and print it out. Script working and printing out a number, only problemes i have, is in my folder i have 2 files but when script print out result i get that is 4 file in directory. What is problems in my script? you see the script here under.
Best regard Joakimuse strict; use warnings; my $directory = 'My directory'; my $file_count=0; opendir (DIR, $directory) or die $!; while (my $file = readdir(DIR)) { if( $file){ $file_count++; } } closedir(DIR); print "Files: $file_count\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: count file in directory
by hdb (Monsignor) on Sep 04, 2013 at 09:06 UTC | |
by joaase (Initiate) on Sep 04, 2013 at 09:23 UTC | |
by marinersk (Priest) on Sep 04, 2013 at 10:34 UTC | |
by hdb (Monsignor) on Sep 04, 2013 at 09:29 UTC | |
Re: count file in directory
by kcott (Archbishop) on Sep 04, 2013 at 09:35 UTC | |
Re: count file in directory
by johngg (Canon) on Sep 04, 2013 at 09:42 UTC | |
by joaase (Initiate) on Sep 04, 2013 at 10:48 UTC | |
Re: count file in directory
by Anonymous Monk on Sep 04, 2013 at 09:39 UTC |
Back to
Seekers of Perl Wisdom