Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Deleting a Temp File

by izut (Chaplain)
on Aug 17, 2006 at 14:15 UTC ( [id://567931]=note: print w/replies, xml ) Need Help??


in reply to Deleting a Temp File

First, you would use File::Temp for create your temporary file, instead writing your own algorithm. Second, you would rely on some user session data, for to associate which file is related to that client. Another approach I think would be nice is using (again) File::Temp with your own prefix - for example, /var/log/mytempfiles - and cron to remove old files in that directory every 10 minutes or so.

Update: Corrected some english mistakes :-)

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^2: Deleting a Temp File
by Anonymous Monk on Aug 17, 2006 at 14:41 UTC
    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?

      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.

      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".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://567931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2024-04-23 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found