How to delete older files by date on Windows 11

You can quickly delete files older than 7, 30, 45, 60 days, etc., using Command Prompt and PowerShell, and here's how on Windows 11.

Windows 11 delete older files X days
Windows 11 delete older files X days
  • To delete files older than 10 days on Windows 11, use the “ForFiles” tool.
  • Use this command: ForFiles /p “FOLDER-PATH” /s /d -10 /c “cmd /c del /q @file”.
  • In the example, change “10” for the number of days you want and the folder path.

On Windows 11, you can use Command Prompt and PowerShell to delete files older than a specific number of days to free up space.

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.

Important: It’s recommended to test these commands using a test folder, as using the incorrect parameters and other mistakes can cause the deletion of the wrong files.

Delete files older than X days using Command Prompt

To delete files older than specific days on Windows 11, use these steps:

  1. Open Start on Windows 11.

  2. Search for Command Prompt, right-click the result and select the Run as administrator option.

  3. Type the following command to delete files older than 30 days on Windows 11 in Command Prompt and press Enter:

    ForFiles /p "C:\PATH\TO\FOLDER" /s /d -30 /c "cmd /c del /q @file"

    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.

    Command Prompt ForFiles

Once you complete the steps, the command will run removing files by checking the creation date you specified.

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:

  1. Open Start.

  2. Search for PowerShell, right-click the result, and select the Run as administrator option.

  3. Type the following command to delete files older than 30 days on Windows 11 in PowerShell and press Enter:

    Get-ChildItem –Path "C:\PATH\TO\FOLDER" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item

    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.

    PowerShell delete older files by date

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.

About the author

Mauro Huculak is a Windows expert and the Editor-in-Chief who started Pureinfotech in 2010 as an independent online publication. He is also been a Windows Central contributor for nearly a decade. Mauro has over 12 years of experience writing comprehensive guides and creating professional videos about Windows, software, and related technologies, including Android and Linux. Before becoming a technology writer, he was an IT administrator for seven years. In total, Mauro has over 20 years of combined experience in technology. Throughout his career, he achieved different professional certifications from Microsoft (MSCA), Cisco (CCNP), VMware (VCP), and CompTIA (A+ and Network+), and he has been recognized as a Microsoft MVP for many years. You can follow him on X (Twitter), YouTube, LinkedIn and About.me.