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:
Action: Start a program
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.