If you are a Windows user and want to delete files older than X days, then you probably want to free up space and keep your files organized. Too many temporary files also consume RAM storages which affect the performance of your system in such condition. Everyone wants their PC to perform best, and deleting old and irrelevant files always helps to speed up the processing speed of the PC.
Here in this post, we will provide three methods to delete files older than 7 days, 30 days, or x days. Before you follow the post till the end, we have organized a chart to help you skip to a specific method:
Workable Solutions | Step-by-step Troubleshooting |
---|---|
Fix 1. Delete Files Older Than X Days with File Explorer |
Press the Win + E keys to open File Explorer. Navigate to the folder containing your files...Full steps |
Fix 2. Delete Files Older Than X Days with ForFiles Command | Left-click the Windows main menu and search for Command Prompt. Right-click...Full steps |
Fix 3. Delete Files Older Than X Days with PowerShell | Left-click the Windows main menu button and search for Windows PowerShell...Full steps |
Recover Automatically Deleted Files with File Recovery Software
Windows auto-deletion feature will automatically delete your files, and if you enable auto-delete files older than 7 days, or 30 days in Task Scheduler, your files will be automatically deleted. You may want to know how to stop Windows 10 deleting files automatically and recover these auto-deleted files on Windows. Unfortunately, most users fail to recover those files manually, and the only option they find is to use a data recovery tool.
If you are looking for reliable data recovery software, we recommend using EaseUS Data Recovery Wizard.
It is one of the most powerful data recovery tools, offering a high recovery rate. Why should you choose this data recovery program?
- It can recover unlimited data from deleted, hidden, and lost. This tool also supports RAW partition recovery.
- It can also be a repair tool and repair corrupted photos, videos, and documents.
- USB recovery, SD card recovery, camera recovery, and memory card recovery are supported.
You can follow three simple steps to recover deleted files with EaseUS Data Recovery Wizard. First, choose the location to start finding the deleted file with the scan feature, and it will allow the user to preview all deleted files of the exact location. Now choose the required files from the preview list and press the recover button to get back that file on your PC. You can check the detailed tutorial below:
Step 1. Select a drive and start scanning
Launch EaseUS Data Recovery Wizard and hover over the partition where you lost data. This could be an internal hard disk, external disk, USB, or SD card. Then, click "Search for Lost Data".
Step 2. Check and preview scanned files
Use the file format filter on the left or upper right corner to narrow the scan results until you find the files you need. Then, you can click the "Preview" button or double-click a file to preview its content, if you'd like.
Step 3. Recover lost data to a secure location
Click the checkbox next to the file and click "Recover" to restore the lost data to your local storage or Cloud drive. We recommend that you do not store the recovered data on the disk where you lost it earlier.
How to Delete Files Older Than X Days [Three Solutions]
There are several ways to delete files older than X days, but here, we will introduce you to the three most effective and straightforward ways. Follow the exact methods we have used to get the best result.
Fix 1. Delete Files Older Than X Days with File Explorer
Here we will guide you on how to delete files older than X days with the help of File Explorer, so follow the steps carefully.
Step 1. Press the Win + E keys to open File Explorer.
Step 2. Navigate to the folder containing your files. In this example, we'll navigate to the "Downloads" folder.
Step 3. Now click on the Date Modified Dropdowns and select a date range per your need, and it will show all the files in that date range.
Step 4. Select the required file you want to delete and click the Delete button on the top bar.
Fix 2. Delete Files Older Than X Days with ForFiles Command
You can quickly delete files older than X days with ForFiles Command. Follow the given steps below to use CMD delete files older than x days:
Step 1. Left-click the Windows main menu and search for Command Prompt. Right-click the result and select the "Run as administrator" option.
Step 2. Type in ForFiles /p "C:\path\to\folder"/s /d -X /c "cmd /c del /q @file" to delete files on Windows that haven't been modified in the last X days and press Enter. In the command, change "C:\path\to\folder" specifying the path to the folder you want to delete files and change /d -X to select files with a 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 (must be wrapped in double quotes). The default is "cmd /c del @file".
/q -allows deleting folders without requiring confirmation.
Fix 3. Delete Files Older Than X Days with PowerShell
If you want to delete many files from different folders and clean up by deleting those older than certain days, then you can do it using PowerShell. Follow the below guide to delete files with PowerShell:
Step 1. Left-click the Windows main menu button and search for Windows PowerShell. Now right-click the result and select Run as administrator.
Step 2. It will open the Windows PowerShell window; now, type in Get-ChildItem –Path "C:\path\to\folder" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-X))} | Remove-Item to delete files that haven't been modified in the last X days and press Enter. Change the path: "C:\path\to\folder" with the folder location; you want to delete and change -X to select files with the last modified date in the above command.
Advanced Tip: How to Delete Files Older Than X Days Automatically with Task Scheduler
Rather than those above three methods, you can also use the Windows Task Scheduler to delete files older than X days automatically. You can set up your computer to automatically delete temp files to save storage space. Follow the exact steps given below to perform this process efficiently.
Step 1. Left-click the Windows button and search for the Control Panel, now click on the System and Security section and choose the Windows Tools option.
Step 2. Now, click on the Task Scheduler to open the Task Scheduler window.
Step 3. In the left panel, click the Task Scheduler Library. Now, click on the Create Task in the right panel.
Step 4. Now a new window titled Create Task will be opened. On the General tab, name it at your convenience.
Step 5. Switch to the Actions tab and click the New button. The New Action window will be opened. There you need to specify the following data.
- Action: Start a program
- Program/script: ForFiles.exe
- Add arguments(optional): /p "%userprofile%\Downloads"/s /d -30 /c "cmd /c del @file"
Step 6. Change the folder path and the number of days to what you want. Now go to the Triggers tab in your task and click on the New button. Under the Begin task, select a schedule in the drop-down list and click the "OK" button. Specify when you want the task to run.
Step 7. It's time to Switch to the Settings tab! Here you need to enable Allow task to be run on demand and the Run task as soon as possible after a scheduled start missed option. Now click OK to create your task. Now it will automatically delete files per your set timing and folder path.
Bottom Line
If you are still following this post, you must know how to delete files older than X days on Windows 11/10. We have provided some of the best possible methods to delete older files effectively. Remember to use EaseUS Data Recovery Wizard to retrieve files on Windows. If you have any doubts regarding the process, feel free to ask us in the comment section; we will help you resolve your issue.
Delete Files Older Than X Days FAQs
Here we have answered some of the frequently asked questions to clarify things better, which might greatly help you!
How do I delete files older than x days Linux?
If you want to delete files older than X days in Linux, use the command "find /path/* -mtime +X -exec rm -rf {} \;.". This command will find the files, and you can quickly delete the required file.
Can I recover automatically deleted files on Windows 11?
Yes, you can recover automatically deleted files on Windows 11. However, to recover deleted files Windows 11, you should take the help of a reliable third-party data recovery tool - EaseUS Data Recovery Wizard.
- 1. Launch this recovery software, and scan your PC.
- 2. Preview the deleted files on Windows 11.
- 3. Recover the files you want.
How do I remove 30 days old files in UNIX?
You just need to know the command, and then you can easily remove 30 days old files in UNIX. We find this command for you, and you just need to type in find /path/to/the/directory/ -type f -name '*' -mtime +30 -exec rm {} \; and then you can remove the unwanted files.
How do you delete files older than x days automatically using PowerShell?
Follow the steps to delete files older than x days automatically with PowerShell:
- 1. Open PowerShell with run as administrator.
- 2. Type in Get-ChildItem –Path "C:\path\to\folder" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-X))} | Remove-Item to delete files automatically.
Was This Page Helpful?
Daisy is the Senior editor of the writing team for EaseUS. She has been working at EaseUS for over ten years, starting as a technical writer and moving on to being a team leader of the content group. As a professional author for over ten years, she writes a lot to help people overcome their tech troubles.
Dany is an editor of EaseUS who lives and works in Chengdu, China. She focuses on writing articles about data recovery on Mac devices and PCs. She is devoted to improving her writing skills and enriching her professional knowledge. Dany also enjoys reading detective novels in her spare time.
Related Articles
-
Laptop Turns Off When Unplugged - How to Fix?
Jerry/2024-10-25
-
Apple Cannot Check It for Malicious Software [Error Solved]
Jaden/2024-10-25
-
How to Fix Grayed Out Folders or Files on Mac
Jean/2024-10-10
-
Reset SMC MacBook Pro | System Management Controller on macOS Ventura/Monterey
Dany/2024-10-25
EaseUS Data Recovery Services
EaseUS data recovery experts have uneaqualed expertise to repair disks/systems and salvage data from all devices like RAID, HDD, SSD, USB, etc.