Skip to main content

We’d like to load Google’s advertising tag to measure how our ads perform. It sets cookies and is optional. Privacy policy.

Mudry
Guides

How to automatically delete old files on Windows

Three ways to automatically delete old files on Windows, which date each one really checks, and how to avoid deleting a file you downloaded yesterday.

Roman Modrytskyi7 min read

Written by the team building Quick File Organizer, folders that organize themselves, by your rules.


If you want to automatically delete old files on Windows, there are three built-in ways to do it: Storage Sense, the forfiles command on a schedule, and a short PowerShell script. All three work. All three also answer the question "how old is this file?" differently, and that difference is how people lose a document they saved last week.

This guide covers each method, the date it actually checks, and a safer pattern that moves files out of the way before anything is gone for good.

Why automatically delete old files at all

Some folders only ever grow. Downloads collects installers you ran once, Temp folders fill with leftovers, and export folders keep every version of every report. Nobody goes back to tidy them, so the clean-up has to happen without you.

The goal is not an empty folder. It is a folder where anything older than a month is something you can afford to lose — and a rule that keeps it that way.

Method 1: Storage Sense

Storage Sense is built into Windows 10 and 11 and needs no scripting.

  1. Open the settings

    Settings → System → Storage, then switch on Storage Sense and click it to see the options.

  2. Choose how often it runs

    Every day, week or month, or only when the drive is low on space.

  3. Set the Downloads rule

    Under "Delete files in my Downloads folder if they haven't been opened for more than", pick 1, 14, 30 or 60 days.

The catch is in that sentence: haven't been opened. Storage Sense judges age by the last time a file was opened, not when it arrived. A setup file you ran once and never touched again is fair game, which is usually what you want. A reference PDF you rely on but last opened two months ago is fair game too.

It also only works on Downloads, the Recycle Bin and temporary files. It cannot clean a project folder, a screenshots folder or a network share. We go into its other surprises in Storage Sense deletes your Downloads folder.

Method 2: forfiles and Task Scheduler

forfiles ships with Windows and can delete files older than a set number of days in any folder. This removes files in Downloads last modified more than 30 days ago:

forfiles /p "%USERPROFILE%\Downloads" /d -30 /c "cmd /c if @isdir==FALSE del /q @path"

The if @isdir==FALSE part matters. Without it, forfiles also matches folders, and del on a folder deletes every file inside it.

To run it on a schedule, open Task Scheduler, choose Create Basic Task, pick a daily or weekly trigger, and set the action to start forfiles with everything after the word as its arguments. Tick "Run task as soon as possible after a scheduled start is missed" so a laptop that was asleep still catches up.

Method 3: PowerShell, with a dry run

PowerShell lets you choose which date to trust and preview the result first:

Get-ChildItem "$env:USERPROFILE\Downloads" -File |
  Where-Object CreationTime -lt (Get-Date).AddDays(-30) |
  Remove-Item -WhatIf

-WhatIf prints what would be deleted without deleting anything. Remove it only once the list looks right. To clean subfolders as well, add -Recurse after -File.

Save the script as a .ps1 file and schedule it the same way as forfiles, with powershell.exe -NoProfile -File "C:\Scripts\clean-downloads.ps1" as the program.

Which date counts as old?

This is where most automatic clean-ups go wrong. Windows keeps three dates on every file, and they disagree more often than you would expect.

DateChanges whenUsed by
Last openedYou open the fileStorage Sense
ModifiedThe contents changeforfiles /d, Explorer's default
CreatedThe file appears in this folderPowerShell CreationTime

Modified dates travel with a file. Extract a ZIP you downloaded this morning and the files inside keep the dates they had when the archive was made — possibly years ago. Copy photos from a phone and they keep the date they were taken. A rule that deletes anything modified more than 30 days ago will happily delete all of them on the next run.

For "arrived more than 30 days ago", the created date is usually the closer match, because copying or extracting a file creates it fresh. It is not perfect either: moving a file within the same drive keeps its original created date. There is no single right answer, only the date that matches what you mean by old.

A safer way to automatically delete old files

Deleting straight away leaves no room for a wrong guess. A two-stage clean-up keeps the convenience and adds a safety net:

  1. Move anything older than 30 days into a folder called Old inside Downloads.
  2. Delete what has sat in Old for another 30 days.

A file you still need surfaces in Old long before it is gone, and the folder you work in stays clean. In PowerShell, stage one is the script above with Move-Item -Destination "$env:USERPROFILE\Downloads\Old" in place of Remove-Item.

Better still is a folder that never piles up. If new files are sorted by type the moment they land — installers in one place, PDFs in another — the clean-up becomes a decision per folder rather than one risky rule for everything. That is the approach in how to organize your Downloads folder.

Common questions

Does Storage Sense delete files permanently?

It removes them without asking first, so treat it as permanent. If a file matters, keep it somewhere other than Downloads, or make sure it has been opened recently enough to stay out of reach.

Can I automatically delete old files on a network drive?

Storage Sense cannot, but forfiles and PowerShell can. Use the full network path in place of the Downloads folder, and run the scheduled task under an account that has permission to delete on that share.

How do I delete only one type of file, like old installers?

Add a mask. With forfiles, put /m *.exe after the folder path. In PowerShell, add -Filter *.exe to Get-ChildItem. Everything else in the folder is left alone.

Was this useful?

Quick File Organizer

Folders that organize themselves, by your rules. Free, no account.

See Quick File Organizer

Keep reading

Know when the next app ships

1 more Windows utility is in development. One short email when each one is ready — nothing else.

Product releases only — roughly once a month. Unsubscribe any time.