Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Re: Range of File Names and For/While Problem

by svsingh (Priest)
on Sep 22, 2003 at 20:41 UTC ( #293276=note: print w/replies, xml ) Need Help??

in reply to Re: Range of File Names and For/While Problem
in thread Range of File Names and For/While Problem

I thought I'd take a quick break from work and see if I could write the File::Find version of this. The following code will create a list of the files modified in the past seven days in d:\log\exported. I didn't backdate the files in my directory to test this thoroughly, but it seems to work.
use File::Find; my $ageLimit = 7; # the age (in days) of the oldest file you want to +process my $ageCutoff = time - $ageLimit * (60*60*24); # the cutoff time my @logFiles = (); my $findFilter = sub { if ( (stat($_))[9] > $ageCutoff ) { # only push files newer than c +utoff push @logFiles, $_; } return; }; find($findFilter, 'd:\log\exported'); # populates the list

Replies are listed 'Best First'.
Re: Re: Re: Range of File Names and For/While Problem
by demerphq (Chancellor) on Sep 22, 2003 at 21:57 UTC

    Dont forget File::Find is recursive. So youll grab all the files that match in sub directories as well, and should it contain a directory thats new enough you'll have a problem as it'll get included as well. Also as you are simply pushing the base name into the list you wont even know whats happening until you start to diagnose missing files and find them two layers deeper in the file structure :-)

    use File::Find; my @files; my $age_limit=7; find { wanted=>sub { -f and -M($_) < $age_limit and push @files, $_ }, no_chdir=>1 }, 'd:\log\exported'; print join("\n",@files),"\n";

    You should take a look at find2perl


    Everybody remember the Gandhi quote?

      First they ignore you, then they laugh at you, then they fight you, then you win.

    Gentlemen and ladies, this newest leaked memo from Microsoft confirms that we are advancing through GandhiCon Three.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://293276]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2021-04-11 21:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found