On Mon, Jul 23, 2001 at 12:05:35PM -0700, Groove Salad wrote:
> Is there a way using Date::Calc to determine all the files in a DIR that 
> have not been accessed or modified in the last xx number of days? I 
> thought it would also require the use of stat().

That's done easily enough, and doesn't require Date::Calc at all.

    #!/usr/bin/perl -w

    use File::stat;
    use strict;    

    my $last_amtime = time() - 2 * 86400; # 2 days


    opendir(DIR, ".") || die("opendir failed: $!\n");
                                                     
    while (defined(my $file = readdir(DIR))) {       
        my $stat = stat($file);

        if ($stat->mtime < $last_amtime || $stat->atime < $last_amtime) {
            print "$file\n";                                             
        }
    }    


This would print any files in the current directory that have not been
accessed or modified in the past two days.  The use of File::stat can be
replaced, at a slight readability expense.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to