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?

4
  • "Not sure if it works" - have you tried? Sep 14, 2017 at 20:58
  • 1
    Have you heard about a tool called "Task scheduler"? Sep 14, 2017 at 20:59
  • I don't know how to make the batch file run automatically though, so I wouldnt be able to test it. Sep 14, 2017 at 21:06
  • 1
    For testing, you can just double click it. No need to run automatically. Sep 14, 2017 at 21:15

1 Answer 1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.