in reply to Re: Deleting a Temp File
in thread Deleting a Temp File

May be a way of deleting the previous created file by it's date in that directory, but how to get the date created of a file?

Replies are listed 'Best First'.
Re^3: Deleting a Temp File
by izut (Chaplain) on Aug 17, 2006 at 15:50 UTC

    I think you can use Unix find command for that. You can also use Perl for that using Find::File or File::Find::Rule. Check also -X and stat for more information on how get the creation date of some file.

    Igor 'izut' Sutton
    your code, your rules.

Re^3: Deleting a Temp File
by graff (Chancellor) on Aug 18, 2006 at 04:11 UTC
    Look at "perldoc -f -X", especially "-M" -- that reports the age of the file in days (a floating point number) relative to the time that the script started. (It's actually based on the date and time of "last modification" of the file, not "creation", but that shouldn't make any difference for you.)

    Also, File::Find (or anything related to it) is overkill if you just have one directory (no subdirectories) where the temp files are kept:

    # get a list of data files that are at least one day old in /my/tmpdir +: opendir( TMP, "/my/tmpdir" ); my @dayold = grep { /[^.]/ and -f and -M _ > 1 } readdir TMP; closedir TMP; # don't like old files? kill 'em off: unlink map { "/my/tmpdir/$_" } @dayold;
    If you want to focus on files that are, say, just 2 hours old or older, use "2/24" instead of "1" to test against the value of "-M".