I will venture forth with some advice:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.