Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day joaase, Welcome to the monastery. In addition to the two files you say you have, you've also got '.' (current directory) and '..' (parent directory). That makes four entries in total. You can check this by printing the directory entries. Something like (code layout tidied):
The readdir documentation has example code for excluding '.' and '..'. Unrelated to your posted issue, I see another problem with:
"if ($file) {" will always be TRUE: you'll never get to that condition if "my $file = readdir(DIR)" is FALSE. As currently written, that test is completely redundant and should be removed (i.e. replace the whole if block with just "++$file_count;". Perhaps you wanted a file test operator in the if condition. For instance, "if (-f $file) {" would check for plain files: '.', '..' and any other directories would not be included in the count; this would resolve your original problem. -- Ken In reply to Re: count file in directory
by kcott
|
|