The Settings app includes Storage sense, a feature that automatically runs when the storage is low in space. Alongside the ability to delete temporary files, you can also enable the feature to delete files in the recycle bin or Downloads folder that haven’t changed in the last 30 days. However, it is limited and doesn’t offer an option to monitor additional folders to delete files that haven’t changed in the previous 60 days. When you store temporary files from the internet or projects in different folders, it’s possible to use the ForFiles command in Command Prompt and Task Scheduler to delete files from any folder older than a specific number of days. In this guide, you will learn the steps to manually delete files that haven’t been modified in a specific number of days and the instructions to create an automated task that will delete files older than a certain number of days inside any folder on Windows 10.

Delete files older than X days using ForFiles on Windows 10 Delete files older than X days automatically using Task Scheduler on Windows 10 Delete files older than X days automatically using PowerShell

Delete files older than X days using ForFiles on Windows 10

If you have different folders with many files and would like to clean up by deleting those older than a certain number of days, you can use the ForFiles command. To use the ForFiles command to delete files older than a certain number of days on Windows 10, use these steps:

ForFiles command breakdown

/p — indicates the pathname to start searching. /s — instructs ForFiles to search inside subdirectories. /d — specifies the last modified date for a file. /c — instructs ForFiles to execute the command (must be wrapped in double quotes). The default is “cmd /c del @file.” /q — allows deleting folders without requiring confirmation. 

If you want to learn more about these switches, use the ForFiles /? Command. In the command, change “C:\path\to\folder” specifying the path to the folder you want to delete files and change /d -30 to select files with a last modified date.

Delete files older than X days automatically using Task Scheduler on Windows 10

The command in the previous instructions allows you to delete files in a folder older than 30 days, but you need to open Command Prompt and execute the command manually whenever you want to free up space. To automate the process, you need to use the Task Scheduler on Windows 10 to create a task that executes the command at specified intervals. To create a scheduled task with the ForFiles commands to delete files that haven’t changed in some time, use these steps: Once you complete the steps, the command will run on the schedule deleting the files older than the number of days you specified. Remember not to change the name or move the folder to another location. Otherwise, the task will fail.

In the command, change “C:\path\to\folder” specifying the path to the folder that you want to delete files and change /d -30 to select files with the last modified date.

Allow task to be run on demand. Run task as soon as possible after a scheduled start is missed. If the task fails, restart every.

		      All content on this site is provided with no warranties, express or implied. Use any information at your own risk. Always backup of your device and files before making any changes. Privacy policy info.