Delete Files Older than N Days Automatically in Windows

Run the command automatically Using Task Scheduler:

  1. Launch Task Scheduler.
  2. In Task Scheduler, click “Task Scheduler Library”
  3. Click “Create task” link on the right pane.
  4. In the “Create Task” dialog, select the “General” tab.
  5. Mention the name of the task, say “Delete older files in My Documents”
  6. Click on the Triggers tab, and click New.
  7. Select “On a schedule” in the drop-down list under “Begin the task” dropdown list box.
  8. You may choose to run the task daily, weekly or monthly. If you choose weekly, select the day(s) of the week when you want the task to trigger.
  9. Once done, click the OK button.
  10. Click the “Actions” tab, and click the “New…” button.
  11. In the “New Action” window, fill in the following:
Action: Start a program
Program/script: C:\Windows\System32\ForFiles.exe
Add arguments (optional): /p "%userprofile%\Documents" /s /d -30 /c "cmd /c del @file"

A new task is created which when run, deletes files in your Documents folder that haven’t been modified in the last 30 days.

Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.