1.

Solve : Date 3 days ago - need to use in batch file?

Answer»

I need to delete old backup files whose names include the date in yymmdd FORMAT. I want to keep the latest 2 so I need to calculate the date 3 days ago to build the filename of the file I want to delete using a DAILY scheduled batch file. Any help will be much appreciated.
I can't see a batch file doing this even under XP.

Why not use the date last modified that you see on a directory list? XCOPY with the /d switch may work for you. The date is a moving target so you would have to prompt for the cutoff date. Check details by typing help xcopy at a command prompt.

An embedded date in the dataset name is a complication. A script would work; though even a script would have some very tricky code.

If you're interested in scripting try:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScript.asp

Good luck. Many thanks for your input, Sidewinder. I'm going to write a Visual Basic program to do the job. However, any further input on this TOPIC is still welcome.Good grief! From a batch file to a VB program. I guess this bus didn't stop in Script Land.

All you really need is the FileSystemObject, a couple of arrays, some sort logic and of course a delete method.

Search your disk for the file script56.chm. If you don't have it, you can get it at:

http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

It's a COMPLIED help file for scripting and includes FULL details on the FileSystemObject. Cut & Pasting the examples, the script will write itself.

You can Google for "vb bubble sort". Most of them use the "*censored* the torpedos" approach. The array will be sorted whether it needs it or not and there is no trap for exiting if no flips have been made. With low-volume this is not a problem.

Post back if you need assistance.



Discussion

No Comment Found