I am searching for a solution regarding the following problem:

I have a folder with files that are generating at the same time (so deleting by create or last modified date is not working).

The file names are something like this:


So, I need a script that would be able to read through the file names, and understand those last 8 characters as a date. Then to keep in the folder only the newest 5 files and delete all the rest.

I guess it's a bit complicated, but I hope someone can point me in the right direction.

0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.


Pretty straightforward...

There are probably quicker, much more efficient ways but I like to split problems into logical pieces so that, if you get a wrong result, it's simpler to track down where the error is.

- Use the MID function to extract everything starting at character 4, ending at character 12
- Use either LEFT, RIGHT or MID to split the resulting string into day, month and year parts
- Build a proper date string from these constituent parts
- Compare this date with today minus 5 days
- Act accordingly
- Take your "developer education" baseball bat round to whichever idiot decided on the totally wrong-headed filename format and begin lessons. Anyone with even half a brain, who thought about a naming convention for even a nanosecond, would have realised that AAAYYYYMMDD.xxx is the most sensible format.
Answered 04/28/2010 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity