in reply to Perl Script to count files and directories is not working.
Also, perltidy is handy for indenting your code.
use strict; use warnings; use File::Slurp; my @dirs = ('./'); my $directory_count = 0; my $file_count = 0; my $outfile = 'log.txt'; open my $fh, '>', $outfile or die "can't create logfile; $!"; for my $dir (@dirs) { for my $file (read_dir($dir)) { if ( -f "$dir/$file" ) { $directory_count++; } else { $file_count++; } } print $fh "Directories: $directory_count\n"; print $fh "Files: $file_count\n"; } close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Script to count files and directories is not working.
by manu_06 (Novice) on Aug 27, 2010 at 18:27 UTC |