Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

batch script to delete old files

42 views
Skip to first unread message

fred.y...@gmail.com

unread,
Feb 7, 2008, 5:04:36 PM2/7/08
to
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?

billious

unread,
Feb 7, 2008, 9:18:59 PM2/7/08
to

<fred.y...@gmail.com> wrote in message
news:2f70f3b6-f4a3-4728...@d70g2000hsb.googlegroups.com...

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!


Todd Vargo

unread,
Feb 7, 2008, 11:40:37 PM2/7/08
to
billious wrote:

> First, try alt.msdos.batch.nt as NT+ batch commands are significantly
> different from DOS/9x which is the target for alt.msdos.batch.

With as many times that this group redirection information is posted per
week, one might think Google posters should have read it at least once
before posting. :-(

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Richard Bonner

unread,
Feb 8, 2008, 1:21:35 PM2/8/08
to
fred.y...@gmail.com wrote:
> 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.

> Any suggestions?

*** This is not a Windows group, but for any version of DOS or Windows:

XXCOPY C:\BACKUP\*.* /DB8D /RS


This will remove source (files) in the BACKUP directory that are 8 or
more days old.


One or more links to XXCOPY can be found at:

http://www.chebucto.ca/~ak621/DOS/Websites.html


Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

0 new messages