The Settings app has Storage sense, a feature that automatically runs when running low on storage to free up space. However, it’s limited and does not provide an option to monitor additional folders to delete files that haven’t changed in the last 60 days. If you store temporary files from the internet or projects in different folders, on Windows 11 you can use the “ForFiles” command in Command Prompt or a PowerShell script 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 on Windows 11.
Delete files older than X days using Command Prompt Delete files older than X days using PowerShell
Delete files older than X days using Command Prompt
To delete files older than specific days on Windows 11, use these steps: Once you complete the steps, the command will run removing files by checking the creation date you specified. In the above command remember to change “C:\PATH\TO\FOLDER” specifying the path to the folder, you want to delete files and change /d -30 to select files with the last modified date.
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, which 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.
Delete files older than X days using PowerShell
To use PowerShell to create a batch to delete files based on the creation date on Windows 11, use these steps: After you complete the steps, the PowerShell script will run, 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 command will not run. Change the “C:\PATH\TO\FOLDER” path with the folder location, you want to delete files and change -30 to select files with the last modified date in the above command.
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.