Marcello has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I count all the files in all subdirectories?
by stefp (Vicar) on Sep 18, 2001 at 00:49 UTC | |
|
Re: How do I count all the files in all subdirectories?
by John M. Dlugosz (Monsignor) on Sep 18, 2001 at 00:52 UTC | |
|
Re: How do I count all the files in all subdirectories?
by blakem (Monsignor) on Sep 17, 2001 at 23:10 UTC | |
by John M. Dlugosz (Monsignor) on Sep 18, 2001 at 00:46 UTC |