Reputation: 535
I'm trying to use bat file as a command for deleting files older than 10 days in a folder. The code is like this:
forfiles -p "E:\folder" -m *.* /D -10 /C "cmd /c del @path"
However, I'm not able to figure out how to get a log file populated everytime it's run. I've tried this below, that works with robocopy, however doesn't work with forfiles.
forfiles -p "E:\folder" -m *.* /D -10 /C "cmd /c del @path" /LOG+:E:\folder\log.txt
Would you know how shall I write this code so I have a log file populated with information of deletion?
Thanks
Upvotes: 1
Views: 12957
Reputation: 7517
/LOG
belongs to robocopy an thus it's not working.
In your example you're also trying to write the logfile into the same folder you are deleting the files from. Perhaps that is wanted, but i'm just saying...
Like following it should work (will only log files which can't be deleted):
forfiles -p "E:\folder" -m *.* /D -10 /C "cmd /c del @path >> E:\anotherfolder\log.txt"
The following will log all files which are processed through forfiles.
(but will not show if deletion was successful or not)
forfiles -p "E:\folder" -m *.* /D -10 /C "cmd /c del @path&echo @path >> E:\anotherfolder\log.txt"
Upvotes: 3