Certainly File::Find can help you out.
#!/usr/bin/perl -w use strict; use File::Find; my @qualifiers = (); my $today = time; my $ten_days = ( 60 # seconds in a minute * 60 # minutes in an hour * 24 # hours in a day * 10 ); # the number of days sub process_file { push @qualifiers, $File::Find::name if is_ten_days_old(); } sub is_ten_days_old { # File::Find has done the following for you: # - chdir to the directory where this file resides # - set $_ to the basename of the file # - set $File::Find::name to the fully-qualified name of the file # Don't check ages on directories. return 0 if -d; # stats $_; ninth item is modification date my $age = (stat(_))[9]; # returns true if old enough, false if not return $today - $age > $ten_days; } find(\&process_file, @ARGV); # Print all the files qualifying: foreach (@qualifiers) { print $_,"\n"; }
Then invoke it like this:
C:> perld tendays.pl C:\this\directory\please
(I think the invocation is right; I 'm a Mac and Unix guy, not Windows. I've run this code on OS X and it works OK there, modulo the file specification syntax being different.) The key is the is_ten_days_old() sub, which tells process_file() which files to keep.

I highly recommend the Perl Cookbook; if you don't have a copy, you should consider getting one. This is a modification of Recipe 9.7, Processing All Files in a Directory Recursively.

You could do it yourself, but File::Find is faster for you to get the job done.


In reply to Re: Recursive Subdirectories by pemungkah
in thread Recursive Subdirectories by pildor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.