If you're a Windows user and wish to delete files older than X days, you likely aim to free up space and maintain an organized file structure. An abundance of temporary files also consumes RAM storage, impacting your system's performance. Everybody desires optimal PC performance, and removing old and unnecessary files consistently contributes to boosting your computer's processing speed.

In this post, we will present three methods to remove files that are older than 7 days, 30 days, or x number of days. Before proceeding through the entire article, we have prepared a table to assist you in jumping directly to a particular method:

Translate into English

Workable Solutions Step-by-step Troubleshooting
Fix 1. Delete Files Older Than X Days using File Explorer

Press Windows key + E to open File Explorer. Navigate to the folder with your files...Complete steps

Fix 2. Delete Files Older Than X Days with the ForFiles Command Click on the Windows main menu, search for Command Prompt, then right-click...Complete steps
Fix 3. Delete Files Older Than X Days using PowerShell Click on the Windows main menu button, search for Windows PowerShell...Complete steps

Recover Automatically Deleted Files with File Recovery Software

Windows' auto-deletion feature will automatically remove your files, and if you have enabled the deletion of files older than 7 days or 30 days through the Task Scheduler, your files will be erased without prompting. You might be interested in learning how to prevent Windows 10 from deleting files automatically and recovering those auto-deleted files on your system. Sadly, most users are unable to manually restore these files, leaving them with the option of using a data recovery tool.

If you're searching for dependable data recovery software, we recommend utilizing the Data Recovery Wizard tool.

It is among the most potent data recovery utilities, boasting a high success rate in retrieving lost data. Why should you opt for this data recovery program?

  • It can recover unlimited data from deleted, hidden, and lost files. This tool also supports RAW partition recovery.
  • It functions as a repair tool, fixing corrupted photos, videos, and documents.
  • Supports recovery for USB drives, SD cards, cameras, and memory cards.

To recover deleted files using the tool Data Recovery Wizard, follow these three straightforward steps: 1. Start by selecting the location where the deleted file was originally stored. Launch the scan feature, which will enable you to preview all the deleted files from that specific location. 2. From the preview list, carefully select the files you wish to recover. Make sure you identify the correct files before proceeding. 3. Once you have chosen the desired files, click on the "Recover" button to restore them to your computer. For a detailed tutorial, please refer to the link below: /recover-deleted-files.html

Step 1. Select a drive and start scanning Select the drive that contains the files or data you want to recover, and initiate the scanning process. The scanning will help in detecting any lost or deleted items on the chosen drive.

1. Launch the "Data Recovery Wizard" tool. 2. Hover the cursor over the partition where you experienced data loss. This can be an internal hard drive, external disk, USB drive, or SD card. 3. Click on "Scan" to initiate the scanning process.

Translation:
Select a location to scan

Step 2. Check and Preview Scanned Files

Utilize the file format filter located in the left or upper-right corner to refine your search results until you locate the required files. Once found, you can click the "Preview" button or double-click a file to preview its contents, if desired.

Choose files to recover
This HTML code represents an image block with a pop-up effect. The image has an alternative text "Choose files to recover," a height of 468 pixels, a width of 700 pixels, and its source is "/images/en/data-recovery/drw-pro/screenshots/recover-lost-data-step2.png". The actual image displays a step in the process of recovering lost data.

**Step 3. Recover lost data to a secure location** Recovering lost data is vital to make sure your precious info isn't gone for good. Once you've found those missing files or data, it's key to restore 'em to a safe spot. Here's how: 1. **Pick a secure storage spot**: Choose a secure place on your computer or an external hard drive to save the recovered files. Make sure there's enough room and it ain't the same place the data vanished from, 'cause it might still be at risk. 2. **Use a solid recovery tool**: If you're using data recovery software, follow its cues to start the recovery. Make sure the software's legit and from a trustworthy source so you don't lose more data. 3. **Preview and choose files**: Before restoring everything, preview the files to check they're good. This helps avoid getting back incomplete or damaged files. Just pick the ones you actually need. 4. **Kick off the recovery**: Once you've picked the files to save, start the recovery. The software should move 'em to your chosen safe spot. 5. **Backup, backup, backup**: After you've got your data back, back it up to guard against future loss. Cloud services, external drives, or another partition on your hard drive work great. 6. **Keep backups fresh**: Set up a schedule to keep your backups current. That way, if anything happens again, you've got the latest version of your important files. By doing this, you'll not only get your data back but also keep it safe and ready for later.

Check the box next to the file and click "Recover" to restore the lost data to a secure location. It's recommended that you do not save the recovered data on the same disk where it was initially lost.

Recover lost data

How to Delete Files Older Than X Days [Three Solutions]

There are multiple approaches to deleting files that are older than a specific number of days, but in this guide, we will present you with the top three most efficient and straightforward methods. Follow the exact steps outlined to achieve the best results.

Fix 1. Delete Files Older Than X Days Using File Explorer

Here, we will guide you on how to delete files that are older than X days using File Explorer. Please follow the steps diligently.

Step 1. Press the Win + E keys to open File Explorer.

Step 2. Navigate to the folder where your files are located. In this example, we will go to the "Downloads" folder.

Step 3. Next, click on the 'Date Modified' dropdowns and choose a date range as per your requirement. It will display all the files within that specified timeframe.

Sort Files by Date in Windows File Explorer

Step 4. Select the file you wish to delete and click the Delete button located on the top bar.

Fix 2: Delete Files Older Than X Days Using the ForFiles Command

You can efficiently remove files that are older than X days using the ForFiles Command. To delete files via CMD that are older than a specified number of days, follow the steps outlined below:

Step 1. Click the Windows main menu, 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, then press Enter. In this command, replace "C:\path\to\folder" with the actual path to the folder where you want to delete files, and modify "/d -X" to specify the number of days since the file was last modified.

Type in ForFile Commands to delete files older than x days

ForFiles command breakdown The `ForFiles` command is a powerful utility in Windows Command Prompt that allows you to perform actions on files based on certain criteria. Here's a breakdown of its syntax and components: ```markdown ForFiles [/P ] [/M ] [/C ] [/D <+|->] [/M] [/S] ``` 1. `/P `: Specifies the starting directory for the search. Replace `` with the actual directory path. 2. `/M `: Defines the file mask to filter the files. Use wildcards like `*` and `?`. For example, `*.txt` would find all text files. 3. `/C `: Executes the specified command for each file found. Enclose the command in quotes if it contains spaces. Common commands include `cmd /c echo @file` to print the file name or `cmd /c del @file` to delete the file. 4. `/D <+|->`: Filters files based on their last modified date. `` can be a positive or negative integer. `+` means files modified within the specified number of days, while `-` means files modified that many days ago. 5. `/M`: This switch is used to indicate that the following parameter is the search mask, but it's usually not needed since `/M` is implied when a mask is provided. 6. `/S`: Enables recursive searching through subdirectories. Here's an example usage: ```cmd ForFiles /P "C:\Users\Username\Documents" /M "*.txt" /C "cmd /c echo @file" ``` This command will list all `.txt` files in the "Documents" folder and its subfolders.

/p - indicates the starting pathname for the search.

/s - tells ForFiles to search within subdirectories.

/d - specifies the last modified date for a file.

"/c" - tells ForFiles to execute the specified command (must be enclosed in double quotes). The default is "cmd /c del @file".

/q - allows deleting folders without requiring confirmation.

Solution 3: Remove Files Older Than X Days Using PowerShell

If you wish to delete numerous files across different folders and perform a cleanup by removing files older than a specific number of days, you can achieve this using PowerShell. Please follow the guide below to learn how to delete files with PowerShell:

Step 1. Click the Windows main menu button, search for Windows PowerShell, then right-click the result and choose "Run as administrator."

Step 2. This 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 then press Enter. Replace the path "C:\path\to\folder" with the actual folder location you want to delete files from, and change -X with the number of days to specify the last modified date range for the files to be removed.

delete files older than x days with PowerShell

Advanced Tip: How to Automatically Delete Files Older Than X Days Using Task Scheduler

Instead of the above three methods, you can also utilize the Windows Task Scheduler to automatically delete files that are older than a specified number of days. This allows you to configure your computer to automatically remove temporary files, thereby conserving storage space. Adhere to the precise steps outlined below to efficiently carry out this task.

Step 1. Left-click on the Windows button, search for the Control Panel, then click on the System and Security category and select the Windows Tools option.

Step 2. Next, click on Task Scheduler to open the Task Scheduler window.

Step 3. In the left panel, click on "Task Scheduler Library". Next, click on "Create Task" in the right panel.

Step 4. A new window called "Create Task" will open. On the "General" tab, give it a name of your choice.

Step 5. Switch to the Actions tab and click the New button. The New Action window will open. Here, you need to specify the following information.

  • Action: Launch a program
  • Program/script: ForFiles.exe
  • Add arguments (optional): /p "%userprofile%\Downloads" /s /d -30 /c "cmd /c del @file"

Automatically delete files older than x days with Task Scheduler

Step 6. Modify the folder path and the number of days according to your preferences. Next, navigate to the Triggers tab within your task and click on the New button. Under the "Begin the task" section, select a schedule from the drop-down list and then click the "OK" button. Specify the desired time for the task to run.

Step 7. It's time to head over to the Settings tab! Here, you need to enable the "Allow task to be run on demand" and "Run task as soon as possible after a scheduled start is missed" options. Once done, click OK to create your task. From now on, it will automatically delete files based on the specified timing and folder path.

Bottom line, conclusion

If you're still reading this post, you must be wondering how to delete files older than X days on Windows 11/10. We've shared some of the most effective methods to accomplish this task. Don't forget to utilize tools like Data Recovery Wizard to recover files on Windows if needed. If you have any questions about the process, please feel free to ask in the comments section; we'll be glad to assist you in resolving your issue.

"Delete Files Older Than X Days" FAQs

Here, we have addressed some frequently asked questions to provide better clarification, which could be of great assistance to you!

How do I delete files older than x days in Linux?

To delete files older than X days in Linux, use the command: `find /path/* -mtime +X -exec rm -rf {} \;`. This command will search for files that are older than X days and promptly remove them. Ensure you replace `/path/` with the actual directory path, and X with the desired number of days.

Can I recover automatically deleted files on Windows 11?

Yes, you can recover automatically deleted files on Windows 11. However, to recover deleted files on Windows 11, you should seek assistance from a trustworthy third-party data recovery tool - tools Data Recovery Wizard.

    1. Launch the recovery software and scan your PC. 2. Preview the deleted files on Windows 11. 3. Recover the desired files.

How do I remove files older than 30 days in UNIX?

All you need is the correct command, and you can effortlessly delete files that are 30 days old in UNIX. We've found the command for you, simply type in find /path/to/the/directory/ -type f -name '*' -mtime +30 -exec rm {} \; and those unwanted files will be removed with ease.

How do you delete files older than x days automatically using PowerShell?

Follow these steps to automatically delete files older than x days using PowerShell: 1. **Open PowerShell**: - Press `Win + X` on your keyboard and select 'Windows PowerShell' (or 'PowerShell' if you're using Windows 11) from the menu. 2. **Change Directory**: Navigate to the folder where you want to delete old files. For example, if your folder is located in `C:\Users\YourUsername\Documents`, type: ``` cd C:\Users\YourUsername\Documents ``` Replace `YourUsername` with your actual username. 3. **Create a Script**: Open a text editor like Notepad and paste the following script, replacing `x` with the number of days you want as your threshold: ```powershell $DaysOld = x $Path = "C:\Users\YourUsername\Documents" # Replace with your folder path $DateLimit = (Get-Date).AddDays(-$DaysOld) Get-ChildItem -Path $Path -Recurse -File | Where-Object { $_.LastWriteTime -lt $DateLimit } | Remove-Item -Force ``` Save the file with a `.ps1` extension, for example, `DeleteOldFiles.ps1`. 4. **Run the Script**: Go back to PowerShell, and make sure you're still in the correct directory. Now, type: ``` .\DeleteOldFiles.ps1 ``` Press Enter to execute the script. You might get a security warning; type `A` and press Enter to confirm running the script. 5. **Confirm Deletion**: PowerShell will prompt you to confirm the deletion of each file. Type `Y` and press Enter to proceed, or `N` to skip any file. 6. **Execute Automatically**: If you want to run this script automatically, you can create a scheduled task in Task Scheduler. To do that, follow the Task Scheduler instructions specific to your version of Windows. Remember to be cautious when deleting files, as this process cannot be undone. Always make backups before executing such scripts, especially if dealing with important data.

    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 automatically delete files.