1). Use gmt (UTC) - dealing with local time and DST vs regular time is a mess. Eliminate that by only using UTC. Convert to local time only for user presentation when necessary.
2). Use a directory name format that is sortable by normal alphanumeric sort: YYYYMMDD if month is 1, then use 01. If day is 9, use 09. A date in this format can be compared and sorted against other dates using just a simple cmp instruction. Leading zeroes matter.
3). I would only use the "easily visible stuff", ie, the directory name (probably an easily parse-able part of that name). Although you are going to be creating directories on the "right dates", etc. and the -M time, etc should be the same, go with the name of the file. We want to have things that happen in the most obvious way possible and the obvious ways for users to list the files work should work. Please pay attention to (1) and (2).
I hope these 3 points will save you a lot of grief!
So, each dir name should have an easy way to parse YYYYMMDD out of it. Calculate the oldest YYYYMMDD date as a string that you want to keep. Use string compares of the regex captured date string of the file/directory name to decide whether this file/directory should be kept or not.
delete (this file/directory) if ($thisdate lt $oldestdate);
In reply to Re: Delete Old Directories
by Marshall
in thread Delete Old Directories
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |