If you want to delete files older than X days automatically in Windows 11 and Windows 10, here is how you can do that. It is possible to delete all the files older than a specific number of days from your computer with the help of Storage Sense and ForFiles command. In this post, we will show you how to delete files older than X days (say 7, 10, 30, etc. days) using Storage Sense or ForFiles command line in Windows 11/10.
As said, there are mainly two ways to delete files older than X days in Windows 11/10: using Storage Sense and ForFiles command. Both methods have some advantages and disadvantages. For example, you can run Storage Sense at the preset time only. On the other hand, you can run the ForFiles command at any interval.
How to delete Files older than X days using Storage Sense
To delete Files older than X days automatically in Windows 11/10 using Storage Sense, follow these steps:
- Press Win+I to open Windows Settings.
- Go to System > Storage > Storage Sense.
- Toggle the Automatic User content cleanup button.
- Expand the Run Storage Sense menu and select an option.
- Click the Run Storage Sense now button.
To learn more about these steps, continue reading.
First, press Win+I to open Windows Settings and go to System > Storage > Storage Sense. Then, toggle the Automatic User content cleanup button to turn it on.
Next, you need to select an option from the Run Storage Sense list.
It is recommended to choose a timing that suits your needs. For your information, you can select Every day, Every week, and Every month.
Once done, you can click the Run Storage Sense now button.
It will delete all the files older than the selected time.
However, the problem with Storage Sense is that you cannot choose any specific folder. Let’s assume that you want to delete files older than 30 days from only one folder or one drive. In situations, you can use the ForFiles command.
How to delete Files older than X days using command line
To delete Files older than X days in Windows 11/10, follow these steps:
- Search for cmd in the Taskbar search box.
- Click the Run as administrator option.
- Click the Yes button.
- Enter the following command: ForFiles /p “folder-path” /s /d -30 /c “cmd /c del /q @file”
Let’s check out these steps in detail.
To get started, you need to open the Command Prompt with administrator privilege. For that, search for cmd in the Taskbar search box, click the Run as administrator option, and click on the Yes button.
Then, enter this command:
ForFiles /p "folder-path" /s /d -30 /c "cmd /c del /q @file"
Don’t forget to replace the folder-path with the original folder path, and /d -30 with the time you want. If you want to delete files older than 100 days, enter /d -100.
Once you do that, all the files older than the predefined days will be removed immediately and permanently.
For your information, you can schedule the ForFiles command. That said, you can automatically delete files older than X days in Windows 11/10 using Task Scheduler. However, when you will create the Batch file, you must enter this command:
ForFiles /p "folder-path" /s /d -30 /c "cmd /c del /q @file"
Read: How to delete files and folders using Command Prompt
How do I automatically delete files older than x days?
To automatically delete files older than X days in Windows 11/10, you can follow the aforementioned guides. It is possible to use Storage Sense to get the job done. However, if you need flexibility, you can opt for the ForFiles command. Either way, you do not need third-party apps.
Read: How to delete files and folders using Windows PowerShell
How do I delete files older than 10 days?
To delete files older than 10 days in Windows 11 or Windows 10, you can use the ForFiles command. First, open the Command Prompt with administrator rights. Then, enter this command: ForFiles /p “folder-path” /s /d -10 /c “cmd /c del /q @file”. It will remove all the files older than 10 days only.
Read next: How to sort Files by Extension into separate Folder in Windows.