Avatar of Bert2005
Bert2005Flag for United States of America

asked onย 

How do I edit my batch file so it leaves a certain amount of days of daily files?

I have written a batch file, which used to work on a previous server with a similar path. This one is changed to reflect the new path.

E:\Program Files (x86)\Amazing Charts\Backup

forfiles /p "E:\Program Files (x86)\Amazing Charts\Backup" /s /m *.* /c "cmd /c Del @path" /D -3

This work fine, ย but it deletes all of the files in the Backup folder. It doesn't leave three.

forfiles /p "E:\Program Files (x86)\Amazing Charts\Backup" /s /m *.* /d -3 /c "cmd /c Del @path"

This one also works, it just wipes out all of them.

It is clearly that the part of the batch file telling Windows to leave three files is not working properly.

Any help would be appreciated.

Bert
Windows Batch

Avatar of undefined
Last Comment
NVIT
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bert2005
Bert2005
Flag of United States of America image

ASKER

Yep, it was going by dates not total amount. I did another backup, and it left that backup as it wasn't three days old. I was close with the 27th.

Thanks.

Bert
Avatar of NVIT
NVIT
Flag of United States of America image

Your welcome ๐Ÿ˜Š. Have a great day/night.
Windows Batch
Windows Batch

Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

13K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo