I have a problem, I currently do this to count all the files in all available directories (a directory ONLY contains files, no subdirectories):
This works fine, but there is a little something extra. The directory names are changed very rapidly, so when the script tries to read the contents of a directory, it can already be renamed, and therefore this directory is skipped.my @dirs = dir_entries($dir); foreach $file (@dirs) { my @batches = dir_entries($dir.$file); my $amount = @batches; $total += $amount; } sub dir_entries { my ($dir) = @_; opendir(DIR, $dir); my @entries = readdir(DIR); close(DIR); # Remove . and .. @entries = grep (!/^\./, @entries); @entries = sort {$a cmp $b} @entries; return @entries; }
Anyone has a solution to prevent this from happening?
In reply to How do I count all the files in all subdirectories? by Marcello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |