Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: find "x" quantity newest files in a dir

by mattr (Curate)
on Jun 27, 2001 at 17:03 UTC ( [id://91902]=note: print w/replies, xml ) Need Help??


in reply to find "x" quantity newest files in a dir

Like, I *love* Date::Manip, that's just me I lllllike it. But if you don't have holidays inputted correctly (especially if you aren't in the U.S.) or hey they added another holiday, well you only have 9 files.

So why not just keep 13 or 14 files? Is each one so huge that you are going to wreck your partition? Laziness is a virtue in Perl and saves you time too. I'm going to stick to that and not post any code! :)

Also, I would say don't worry so much about dates. You have a process that is generating a file a day, *if* it's running. Count how many files you have in the directory once a day and unlink the last one. You might even be able to parse the file names to be sure, because what if someone touches one, or you do a recovery from backup. If these are important files look at what is the easiest way to ensure your integrity.

The easiest way I can think of doing that if you are in control of file naming is to name files in sequential order, sort the file names, and determine the next file number. Perhaps you could even use time(). Otherwise if you are really sure you want to get rid of the oldest file, -M or stat will do the age checking part (in unix anyway, don't quote me for Windows).

  • Comment on Re: find "x" quantity newest files in a dir

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found