Delete Files Older than N Days Automatically in Windows
Run the command automatically Using Task Scheduler:
- Launch Task Scheduler.
- In Task Scheduler, click “Task Scheduler Library”
- Click “Create task” link on the right pane.
- In the “Create Task” dialog, select the “General” tab.
- Mention the name of the task, say “Delete older files in My Documents”
- Click on the Triggers tab, and click New.
- Select “On a schedule” in the drop-down list under “Begin the task” dropdown list box.
- 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.
- Once done, click the OK button.
- Click the “Actions” tab, and click the “New…” button.
- In the “New Action” window, fill in the following:
1 2 3 |
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