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

Bert2005
Bert2005 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
End-user support
Commented:
> ...part of the batch file telling Windows to leave three files is not working properly.

Clarification: Files 3 days old and older will be deleted

What you have looks fine.

Author

Commented:
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
NVITEnd-user support

Commented:
Your welcome 😊. Have a great day/night.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial