Are there directories inside the directories? If so, I don't think the file glob method will count them all. It will just count the files inside the top-level directory (it will count directories, too, but not go down inside them).
I'd do something like this:
use File::Find; my $category; for my $file (@file_list) { my $file_path = dirname($file); # better make sure this is working! my $count = CountFiles($file_path); if ($count < 200) { $category = "paper"; } else { $category = "collection" } } # Count all files contained inside a directory, recursively sub CountFiles { my $dir = shift; my $count = 0; find( sub { if (-f) { # only count regular files ++$count; } }, $dir); return $count; }
Note that this way you can do things like not count zero-length files, or ignore symbolic links, etc. by simply changing the file test performed inside the 'find'.
In reply to Re: Counting files in a folder
by scorpio17
in thread Counting files in a folder
by JKasting
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |