To follow your general program logic, but with the help of File::Find::Rule and File::DosGlob, the latter of which is a core module:
#!perl use strict; use warnings use autodie; # errors with open, chdir, etc are now fatal use File::Find::Rule; use File::DosGlob 'glob'; my $search = shift || 'c:/Documents and Settings/user/Desktop/newbatch +2' ; my $outfile = 'c:/Documents and Settings/user/Desktop/newbatch/log.txt +'; open my $outf, '>', $outfile; for my $dir (File::Find::Rule->dir->in($search)) { for my $file ( <*>) { my $path = "$dir\\$_"; print " $path\n"; if (-f $path) { if ($file ne 'empty.txt' and $file ne 'sample.txt') { unless (-s $path) { print $outf "Warning: $path has size ZERO\n"; } } } } }
OR, to be more concise:
#!perl use strict; use warnings; use autodie; use File::Find::Rule; use File::DosGlob 'glob'; my ($search) = @ARGV or die "need a directory to search"; sub found { my ($name, $path, $full) = @_; warn "Warning: $full has size ZERO" # outputs to STDERR unless $name ~~ ['empty.txt', 'sample.txt']; # Perl v5.10+ # unless $name eq 'empty.txt' or $name eq 'sample.txt'; } File::Find::Rule->file->empty->exec(\&found)->in($search);
In reply to Re: Perl Log File Help
by Anonymous Monk
in thread Perl Log File Help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |