1

I am wondering if someone can tell me how I can make a folder in windows that will automatically delete any files within that have been there for more than 'n' days, say maybe 7 for a week.

I have found a similar question that was answered well here, though im not sure if it works on windows 10. Also, would this be a '.bat' file? And, how do I make the batch file run automatically?

Thanks!

Edit: I created a .bat file, starting with the mentioned answer:

forfiles /p "C:\what\ever" /s /m *.* /D -<number of days> /C "cmd /c del 
@path"    

Which I changed to:

forfiles /p "F:\Movies" /s /m *.* /D -<1> /C "cmd /c del @path"

exactly, to test it. The folder 'Movies' has a bunch of things whos date modified is from very long ago. I created a task with Task Scheduler (Thanks Thomas) and it didnt delete anything.

I also tried running the batch manually, tried changing it to 1 minute, tried putting it in the folder that its deleting from, and ran it as admin. Nothing worked. I have permissions on the folder.

Does anyone have any suggestions? Did I do something wrong with the code?

user2809114
  • 97
  • 4
  • 15

1 Answers1

1

I realized that I interpreted the command incorrectly. forfiles /p "F:\Movies" /s /m *.* /D -<1> /C "cmd /c del @path" should have been forfiles /p "F:\Movies" /s /m *.* /D -1 /C "cmd /c del @path", where the - is -1 , not -<1>. Thanks to the helpful comments, I was able to do what I wanted, using the task scheduler to run this, now working, script. Thanks.

user2809114
  • 97
  • 4
  • 15