Well, I got into that, and mentioned there was an easier way, but I never
gave you the easier way to find file ages did I?

Actually, in reading that directory, you can use -M to find the age in days
of a file. This will be in decimal, so to get an integer age, use the int
function. Something like this:



opendir (TEMP, "$ENV{TEMP}");

foreach (readdir TEMP){

        $ddd =  -M "$ENV{TEMP}/$_";
        $ddd = int($ddd);
        print "$_ is $ddd old \n" if ($ddd >=7);

}

In that case, that's quite a bit easier than using Date::Calc.

Steve H.

-----Original Message-----
From: Steve Howard [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 23, 2001 9:24 PM
To: Groove Salad
Cc: [EMAIL PROTECTED]
Subject: RE: newbie: Date::Calc Question


In answer to the question, yes it can. This may not be the easiest way to do
this, but doing it with Date::Calc, I would probably do something like this:

# reading the directories in my temp directory
# which is defined by an environment variable
# and accessed as $ENV{TEMP}

opendir (TEMP, "$ENV{TEMP}");

        foreach (readdir TEMP){

        my @time = qw(sec min hour mday mon year wday yday isdst);
        my %th;
        @th{@time} = localtime((stat("$ENV{TEMP}/$_"))[9]);

        $th{year} += 1900;
        $th{mon}++;

        $dd = Delta_Days(@th{year, mon, mday},Today());
        print "$_ has not been accessed for $dd days\n";

}

So far as Delta_Date goes, all you need is a list like (year1, mon1, day1,
year2, mon2, day2) as an argurment. Since the file's access date is earlier
than today, in order to get a positive number I list it first. The six
argurments are given in that case by the hash slice (@th{year, mon, mday})
for the file modify date, and the Today() function for the second set of
three arguements.

Delta_Date is only one function from the Date::Calc module. It is one way to
do what you asked but actually may not be the easiest in this case, but
Date::Calc is still a very cool tool for working with dates. Read through
it's perldoc - it is a very good doc, and you will see what kind of tools it
really offers.

Hope this helps,

Steve H.

-----Original Message-----
From: Groove Salad [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 23, 2001 2:06 PM
To: Steve Howard
Cc: [EMAIL PROTECTED]
Subject: newbie: Date::Calc Question


Hi,

I've been reading the latest post regarding the Date::Calc module with
great interest.

My question is this:
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().

Thanks in advance,

gS

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


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


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

Reply via email to