By creation date

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
  • To delete files older than 10 days on Windows 11, use the ForFiles tool.
  • Use this command: ForFiles /p “C:\path\to\folder” /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.