
Batch file to delete files older than N days
Ok was bored a bit and came up with this, which contains my version of a poor man's Linux epoch replacement limited for daily usage (no time retention):
7daysclean.cmd
USAGE
: Change 7 for the number of days to keep.
: This is the starting directory to check for files.
NOTES
This is non-destructive code, it will display what would have happened.
Change :
to something like :
so files actually get deleted
February: is hard-coded to 28 days. Bissextile years is a hell to add, really. if someone has an idea that would not add 10 lines of code, go ahead and post so I add it to my code.
epoch: I did not take time into consideration, as the need is to delete files older than a certain date, taking hours/minutes would have deleted files from a day that was meant for keeping.
LIMITATION
epoch takes for granted your short date format is YYYY-MM-DD. It would need to be adapted for other settings or a run-time evaluation (read sShortTime, user-bound configuration, configure proper field order in a filter and use the filter to extract the correct data from the argument).
Did I mention I hate this editor's auto-formating? it removes the blank lines and the copy-paste is a hell.
I hope this helps.
-
-