in reply to Deleting files

Some have suggested using -M $filename. This will return a number of days between the file's last modification and the time your perl program started (which will be negative if the file was modified after your program started).

This is probably what you want to check, e.g. with:

unlink grep -f $_ && -M _ >= 5, glob "$dirname/*";
(see -f, -M, glob, and grep in perlfunc).

But, if your program ran today at 11:00, files modified before 11:00 5 days ago would be deleted, and files modifiedd after 11:00 would not. Your wording "older than five days from the days date" makes me think you may be asking to decide based on just the date of modification, not the time. That's a little more complex.

Replies are listed 'Best First'.
Re: Re: Deleting files
by welchavw (Pilgrim) on Feb 02, 2004 at 18:11 UTC

    Yes, true. The naive application of -M only works for the simple case of an app that doesn't run for very long. A follow-up I'm interested in is this...is localization of $^T recommended to test against the instantaneous current time?

    Regards,
    welchavw