3 Ways to Automatically Delete Older Files on Windows
I’ve often found myself deleting files or folders I thought I no longer needed—only to realize later that I did. Sure, the Recycle Bin offers a safety net, but I like keeping it clean.
Think of it like household trash: I toss things into the outside bin, but once it’s hauled to the curb, it’s gone for good.
Sometimes, I want to clear out files that are just taking up space but I’m not 100% sure I won’t need them soon.
For this, I created a separate folder on another drive partition where I store temporary files. My goal? Automatically delete anything older than 30 days.
In this article, I’ll show you two ways to automate file cleanup in Windows 11:
- Using a simple script with Task Scheduler
- Leveraging Storage Sense to manage Recycle Bin and Downloads folder
Method 1: Automatically Delete Files Using a Script
Windows includes a powerful command-line tool called ForFiles that can delete files based on their age. Here’s how to use it.
Step-by-Step: Manual Cleanup with ForFiles
- Open Command Prompt as Administrator.
- Run the following command:
ForFiles /p “C:\path\to\folder” /s /d -30 /c “cmd /c del /q @file”
- Replace “C:\path\to\folder” with your target folder.
- Change -30 to the number of days you want to keep.
- This command deletes files older than 30 days
ForFiles Command Breakdown
- /p
- Patch to search
- /s
- Include subdirectories
- /d
- Days since last modified
- /c
- Command to execute
- del /q @file
- Quiet delete of each file
Always test this command on a sample folder first to avoid accidental data loss.
Method 2: Automate with Task Scheduler
To run the ForFiles command automatically on a schedule:
Create a Scheduled Task
- Open Task Scheduler.
- Create a new folder (optional) for organization.
- Right-click the folder and choose Create Task.
- Under General, name your task and select:
- “Run whether user is logged on or not“
- Uncheck “Do not store password“
- Go to Triggers tab:
- Click New
- Choose a schedule (Daily, Weekly, etc.)
- Go to Actions tab:
- Click New
- Choose “Start a program“
- Program/script: ForFiles
- Add arguments:
/p “C:\path\to\folder” /s /d -30 /c “cmd /c del /q @file”
- Under Settings, check:
- “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…“
- Click OK and enter your admin credentials if prompted.
- Your task will now run on schedule and clean up older files automatically.
Method 3: Use Storage Sense
Windows 11 includes Storage Sense, a built-in feature that automatically deletes temporary files and manages cloud content.

Enable Storage Sense
- Go to Start > Settings > System > Storage.
- Turn on Storage Sense.
- Click Configure Storage Sense or run it now.
- Set preferences for:
- Temporary files
- Recycle Bin cleanup
- Downloads folder cleanup
Note: Storage Sense doesn’t monitor custom folders, so use it alongside the ForFiles method for full coverage.
Word of Caution
Automated deletion is powerful—but risky. Always back up important data and test scripts before applying them to critical folders. Mistakes can result in permanent data loss.
Conclusion
Whether you’re managing temporary project files or just keeping your system tidy, automating file cleanup in Windows 11 can save time and disk space.
Use Storage Sense for built-in cleanup, and ForFiles with Task Scheduler for custom folders.
I welcome your thoughts, questions or suggestions on my article on automatically deleting older files or folder on Windows 11.
You may support my work by sending me a tip using your Brave browser or by sending me a one time donation using your credit card.
Let me know if you found any errors within my article or if I may further assist you by answering any additional questions you may have.




