Why doesn’t Disk Cleanup Clear the Temp Folder Contents Completely?

Disk Cleanup (Cleanmgr.exe) is a built-in tool in Windows which offers some useful cleanup options not available in other 3rd party cleanup tools. It can remove superseded device drivers, Temporary Files, Internet Explorer cache, obsolete Windows Updates, Previous Windows Installation (Windows.old) folder, and much more.

But you may be wondering why Disk Cleanup skips deleting some files and folders in your TEMP folder.

Why Does Disk Cleanup Leave Behind Temp Files?

When it comes to deleting Temporary Files, Disk Cleanup by default doesn’t wipe out items that match the following criteria:

  1. Files with Read-Only, System or Hidden attributes
  2. Files which have been accessed in the last seven days
  3. Directories that have been created in the last seven days.

For criteria 2: With a simple registry edit, you can make Disk Cleanup erase all Temporary Files or only the files whose last accessed timestamp is greater than “n” number of days from the current date.

RELATED: How to Delete Files Older than N Days Automatically in Windows

Make Disk Cleanup erase all the Temporary files

Start the Registry Editor and go to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files

In the right-pane, double-click LastAccess.

disk cleanup delete all temp files

Set the value data for LastAccess to 0.

“LastAcess” value represents the number of days that must have elapsed since a file was last accessed or a directory was created for that file or directory to be considered for cleanup by Cleanmgr.exe.

By setting the LastAccess registry value data to 0, you can force Disk Cleanup to clean up all the Temporary Files. It skips files that can’t be deleted — such as files that are currently in use by applications, and the ones you don’t have write access.

To be on the safer side, you may set “LastAccess” to “3” so that Disk Cleanup doesn’t erase the files that have been used in the last three days. “3” is safer because just in case some currently running application has stored the temporary data over there, and you’ve been hibernating the system (instead of shutting it down daily) a lot, lately.

The above is the same registry edit that I wrote about in 2005. It applies to Windows 2000/XP through Windows 10. Ref:  Alter the “LastAccess” value for cleaning the Temporary files using Disk Cleanup utility.

Running Disk Cleanup with the default “LastAccess” value left lots of files and folders untouched.

disk cleanup delete all temp files

Only the folders created (and files accessed) before Oct-25 were cleared — clean up done today, Nov-1.

After applying the registry setting, I reran Disk Cleanup.

disk cleanup delete all temp files

The temporary files are all gone, except the in-use files and folders.

disk cleanup delete all temp files

Temporary files Locations

As a side note, if you clean up Temporary Files when Disk Cleanup is running elevated (“Run as Administrator”), “temporary” files in the following folders and sub-folders are cleared as well, in addition to files and folders in the user’s TEMP directory.

  • %WINDIR%\Temp
  • %WINDIR%\Logs
  • %WINDIR%\System32\LogFiles

I, for one, don’t use 3rd party cleanup and maintenance tools. I still rely on Disk Cleanup for this job — but I do automate it using Cleanmgr.exe switches “/sageset” and “/sagerun.”

One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support, my reader. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

2 thoughts on “Why doesn’t Disk Cleanup Clear the Temp Folder Contents Completely?”

  1. I remember a very long time ago, I installed Internet Explorer 5 and then emptied my TEMP folder before restarting. Naturally, when I restarted, Internet Explorer 5 failed to complete the installation. That was when I discovered that Disk Cleanup would have prevented this fault.


Leave a Reply to nivek Cancel reply