Bat file that would delete files older...

skynet - Mar 18, 2010 at 05:34 AM
 Mark - Mar 20, 2010 at 08:06 PM

OK, so I'm working on a .bat file which will delete backups older specific date. This is what I came up with so far:

echo %date%>log.txt
net use z: \\oldfestini\install$ /user:administrator
: please provide correct password
start z:\callp_backup
start z:\callp_temp
xcopy Z:\CallP_Backup z:\CallP_TEMP /D:06-15-09
del z:\callp_backup
xcopy Z:\callp_temp Z:\callp_backup


As you can imagine, I'll have to change the date every time I want to re-run this file. It's not a perfect solution as I want to schedule this task. But to do so, I would need to have a code which will use current date minus 3 days. I managed to use your suggestion echo %date%>log.txt so now I have a current date stored in the log.txt file. All I need now is a line of code which will replace D:06-15-09 part with reference to date saved in log.txt -3 days so for example everything older than 15.03.2010 (today - 3 days) won't be copied.

Thanks for your support

2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Mar 19, 2010 at 07:02 PM
See this

The solution is at the almost at the bottom of that page