Avatar of Bert2005
Flag 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.

Windows Batch

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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.



Your welcome 😊. Have a great day/night.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck