I would like to automatically delete older files using forfiles

Viewed 31

trying to use forfiles to delete files older than X days old. I used this code:

forfiles -p "C:\Users\jukos\Documents\backup_tekdb" -s -m *.* -d -9 -c "cmd /c del @path"

However, when I run it in a cmd window I get

ERROR: No files found with the specified search criteria.

I am able to see the files listed in the directory when I run this line:
forfiles -p "C:\Users\jukos\Documents\backup_tekdb".
I definitely have files with a modification or creation date older than 9 days so I don't see it as being that it's just not finding them.

1 Answers

You can use this code for delete files older than 9 days

forfiles -p "C:\Users\jukos\Documents\backup_tekdb" -s -m * -d -9 -c "cmd /c if @isdir==FALSE echo @path"

Test this and if work change the "echo" command with "del".

Related