Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
HI,
i have a folder with directories and inside of them i have log files ending with '*.log' .
i need a script in windows batch that will erase all the log files that are older than a week.
and keep the rest.
please advise

use the XCOPY Command
go to start>run>cmd and type in xcopy/?
Building my Computer.
15 yr old Programmer.

We need to know your date layout.
Do this:
echo %date%
If at first you don't succeed, you're about average.M2

M2G is right about needing to know the date layout.
This used to drive me nuts at work.
At first I thought the different layouts were due to different OSs on different (Win) boxes. Wrong. The default layout changes for different users on the same box. I think it depends on security privileges.
Write a little program in C or whatever that always writes the date to stdout in a reasonable format.
Capture it's output in batch scripts.
Guy

ok i have broken my head over what you told me , i managed to look at xcopy command which gives me:
XCOPY /D:m-d-y Copies files changed on or after the specified date.
i have managed to get from running
echo %date% the '03/20/2006'
but now i need in my batch file to run xcopy
lats say if i am running it today it should be XCOPY /D:03/13/2006 so it will keep my weekly log files.
how the hell do i subtract 7 from the date.
please advice

Any 'date math' is messy, at best.
I'm still working on it.
As you have guessed, 'subtracting' is anything but straightforward.
For now, I can show you how to keep the newest X number of log files.
Does that sound helpful?
If at first you don't succeed, you're about average.M2

thanks for everything but i found another strange way to do that.
i will copy everyday log file to a a daily
folder then once a week i will copy that to a weekly folder and thats how i will have a
backup for a week.
thanks

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |