Helge said:
Hallo NG!
W7/64/HP
I have a folder containing more or less files with names YYYYMMDDtext.zip
All filenames differ by the date information only.
I want to keep the 4 youngest ones and delete the older if any - without
a yes/no prompt as a part of my backup strategy.
Consider the case that intermediate dates may be missing by any number.
Ideas? Thanks!
Vy 73! Helge
You can try processing the file names, using some complicated scripting
language.
Or, you could keep a tracking file. For example, say that currently there
are four files that exist. Now, create a text file, call it "tracking.txt".
Copy the names of the four files into it.
21020523text.zip
21020525text.zip
21020526text.zip
21020529text.zip
Each time the backup script runs, it reads the first line of "tracking.txt"
and deletes that file. It also deletes the first line of the file. At
the end of the backup run, the latest file name is added to the end
of tracking.txt. After the backup today we might see...
21020525text.zip
21020526text.zip
21020529text.zip
21020602text.zip
So no actual date parsing is taking place. Just a simple FIFO queue
using a text file for tracking.
My scheme is not very clever. Doesn't take into account a situation
where at least four files exist yet. You can add more logic to the script
that processes "tracking.txt" to fix that if you want. But without
any logic to "build a FIFO", you can fake it pretty simply.
I would write the script in AWK, others would use PERL, and so on.
Many scripting languages - use the one you know. I don't know
many scripting languages.
Paul