Does anyone know how to filter out the 3 ‘newest/latest timestamp’ files from a list where they are not necessarily timestamp consecutive in relevance?
i.e files have:
200120810.xml
200120811.xml
200120611.xml
200120310.xml
200120110.xml
The result list should be
200120310.xml
200120110.xml
I’m listing them here in order, which it is the most likely scenario, but also may need to be sorted?
This is to keep only 3 days worth of files and delete the rest. Once I have result the list, then I can do a batch file to delete those.
delete file “c:\example{name of file whose (modification time of it = (minimum of modification times of files of folder “c:\examples”))of folder “c:\examples”}”
I think that code will actually delete the oldest file, not the other ones…
Let me expand on what we are trying to do:
There is a file generated every half an hour so there can be several files on the same day. The files will not necessarily being generated daily so there may be days with 10+ files (in 30 mins increments), a week without activity, and then another day with other 10+ files. We need to keep only the 3 latest days (not the 3 latest files).
We can figure out which ones correspond to a day by looking at the filename date (and ignore the time):
Q: unique values of (firsts 8 of (names of files of folder “C:\example”))
A: 20121010 20121210 20121215 20121220 20130101
Afte that, I have only been able to go thru the list with an ugly batch file so wondering if there is a way to do it in relevance:
parameter “fullPath” = “c:\example”
parameter “y” = “{ “%22” & concatenation “%22 %22” of (unique values of (firsts 8 of (names of files whose (name of it contains “.xml”) of folder “C:\example”))) & “%22” }”
delete “C:\example\delOldScans.bat”
//appendfile for /f "skip=3 tokens=" %X in ( {(parameter “y”)} ) do del {parameter “fullPath”}%X
appendfile set ctr=0
appendfile :start
appendfile for %%a in ({(parameter “y”)}) do call :maybemove “%%a”
Although I’m realizing this will not work either because the ‘name of files’ return the files in oldest to newest order and I need it the other way around. Mmhh