How do I clear temporary files on Windows?

Use forfiles to preview old files, clear %TEMP% with PowerShell, and confirm space is back with Disk Cleanup.

Windowsdisk-cleanupcleanupFilescmddiskpowershellHigh risk
First inspect %TEMP% so you delete only stale files, then clear the folder from PowerShell.

What this covers

Temporary files pile up from installers, browsers, and apps. They are usually safe to remove, but files currently in use should be left alone. This sequence helps you check first, clean safely, and confirm the space came back.

Symptom

?Windows warns about low disk space, the C: drive fills up even after deleting documents, or %TEMP% has grown to many gigabytes. Apps may also slow down when the temp folder is huge.

Preview old files in your temp folders

Before deleting anything, list what is actually old enough to remove. Point the tool at %TEMP% (run echo %TEMP% in Command Prompt to see the exact path) and set the age cutoff, for example 30 days. The echo action only prints matching paths, so nothing is deleted; if the list is empty, there is nothing safe to clear by age.

Windows' forgotten find -mtime equivalent — selects files by age and runs a command on each one.

Command
$ forfiles /P "C:\Logs" /S /M *.log /D -30 /C "cmd /c echo @path"

Clear %TEMP% with PowerShell

Close running apps and installers first, then empty the current user's temp folder from PowerShell. The command removes items recursively and skips locked files instead of failing the whole run. Success looks like the folder emptying quickly; any remaining files are usually in use and can be cleared after a reboot.

Empty %TEMP% safely from PowerShell to reclaim disk space and clear stale installer caches.

Command
$ Remove-Item "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue

Confirm with Disk Cleanup

Run Disk Cleanup on the system drive, let it scan, and check the Temporary Files category. It should now report little or nothing, and you should see free space recovered. If Disk Cleanup still shows a large Temporary Files entry, some files were locked; reboot and repeat the PowerShell step.

Save a cleanup profile once, then run it unattended on any schedule.

Command
$ cleanmgr /sageset:1
!Clearing temp files is high risk: a running installer, update, or app may be using files in %TEMP%. Close apps first, and never delete the temp folder itself—only its contents. Locked files are skipped; if an app breaks, reinstall or reboot to let it recreate what it needs.

How to confirm it worked

Run Disk Cleanup again: the Temporary Files category should be near zero and free disk space should have increased. No app should report missing temp data.

Sources

  • Remove-Item (Microsoft.PowerShell.Management)
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents -Recurse to delete folders with children, -Force for hidden/readonly items, and -ErrorAction SilentlyContinue behavior.
  • Remove-Item — Delete files and folders
    SS64 · technical · 2026-09-17
    Evidence: Shows Remove-Item with -Recurse and -Force used to delete directory trees.
  • cleanmgr - Windows Commands
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents cleanmgr /sageset:n to configure a saved cleanup profile and /sagerun:n to run it unattended.
  • CleanMgr - Automated Cleanup of Temp Files
    SS64 · technical · 2026-09-17
    Evidence: Explains the sageset/sagerun workflow and the registry location where the cleanup profile is stored.
  • FORFILES - Windows CMD
    SS64 · technical · 2026-09-17
    Evidence: SS64 documents /D -30 as files last modified more than 30 days ago, and shows "cmd /c del @path" as the standard deletion pattern.
  • forfiles | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: Microsoft documents forfiles /D +/-n to select files with last-modified date older/newer than n days, /S for recursion, and /C to run a command per file with @path variables.

Last verified: 2026-09-22

Related guides