We help IT Professionals succeed at work.
Get Started

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

Bert2005 asked
Last Modified: 2019-12-01
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.

Watch Question
End-user support
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE