in reply to filter the files in a folder on the basis of some variable present in them
Hi reciter!
The code below shows how I handle checks to be applied on more than one file:
use File::Find; use File::stat; find(\&checkFile, $path); # loop through all files in my directory #--------------------------------- check to be applied on each file -- +----------- sub checkFile { my $fullfilename = $File::Find::name; my $filesize = stat($File::Find::name)->size; my $filename = $_; # --- check for relevance based on expected filenames if ((! ($filename =~ /_obj_pp_comp.txt/ )) && (! ($filename =~ /ob +j.doc/ ))) { return; } if ($filesize == 0) { print ("<!-- \t\tERROR: file $fullfilename is empty. -->\n"); + return; } if (! -f $filename) { print ("<!-- \t\tERROR: file $fullfilename is a directory. -->\ +n"); return; } analyze($fullfilename); } #--------------------------------- work to be done on each relevant fi +le ------------- sub analyze { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: filter the files in a folder on the basis of some variable present in them
by reciter (Novice) on Jun 10, 2015 at 10:32 UTC |