Computing.Net > Forums > Programming > batch script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch script

Reply to Message Icon

Name: mongar
Date: March 14, 2006 at 08:01:27 Pacific
OS: 2000
CPU/Ram: 520
Product: hp
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: JayJay Programmer
Date: March 14, 2006 at 16:08:14 Pacific
Reply:

use the XCOPY Command

go to start>run>cmd and type in xcopy/?

Building my Computer.
15 yr old Programmer.


0

Response Number 2
Name: Mechanix2Go
Date: March 14, 2006 at 20:50:27 Pacific
Reply:

We need to know your date layout.

Do this:

echo %date%


If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: Guy
Date: March 15, 2006 at 17:06:18 Pacific
Reply:

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



0

Response Number 4
Name: mongar
Date: March 20, 2006 at 12:29:13 Pacific
Reply:

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


0

Response Number 5
Name: Mechanix2Go
Date: March 20, 2006 at 13:29:43 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: mongar
Date: March 21, 2006 at 08:05:22 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch script

batch script to parse filenames www.computing.net/answers/programming/batch-script-to-parse-filenames/15286.html

Batch Script Help Needed www.computing.net/answers/programming/batch-script-help-needed/14475.html

Simple Batch Script help www.computing.net/answers/programming/simple-batch-script-help/12744.html