<fred.yingl
...@gmail.com> wrote in message
news:2f70f3b6-f4a3-4728-b755-748a013acb47@d70g2000hsb.googlegroups.com...
>I have a batch script that runs nightly on WinXP to rename backups
> according to the date in a particular folder. My next step would be to
>
delete all of the backups that are more than 1 week
old. Here is the
> current script that I use to rename the
files:
> IF EXIST filename.bak REN filename.bak filename_%date:~4,2%-
> %date:~7,2%-%date:~10%.bak
> Any suggestions?
Certainly.
First, try alt.msdos.batch.nt as NT+ batch commands are significantly
different from DOS/9x which is the target for alt.msdos.batch.
Then read previous articles and solutions offered. This question gets asked
in various forms about once or twice per week.
The basic solution would be something line
for /f "skip=?tokens=*" %%i in ( ' dir /b /o:-d filename*.bak ' ) do ECHO
del "%%i"
where
ECHO is there to show what the batch would do. Once you're satisfied it's
acting correctly, take the ECHO keyword out to activate the delete
? is replaced by the number of generations you want to keep
Note also that it's considered wiser to format your date/time portion as
YYYYMMDDHHMMSSHS since that way the date format is obvious to everyone,
default sorting by name automatically sorts by date and there becomes no
need to ask significant questions like "what date/time format do you use?"
Also, see Timo Salmi's FAQ (see his sig) about dealing with date formatting.
The scheme you have chosen to use is not necessarily universally applicable
as the format returned by %date% depends on individual user settings. This
may or may not be significant in your case.
Happy batching!