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

Disk Cleanup (Cleanmgr.exe) is a built-in tool in Windows that 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 and how to fix it.

Cause

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.

Temp folder filled with DISM servicing files — e.g., DismHost.exe and others

Each time you run Disk Cleanup and cleanup system files, old drivers, or Windows Update files, Disk Cleanup runs DISM in the background, which in turn copies the DISM servicing files to a subdirectory in your Temp folder.

dism servicing files in temp folder

However, neither Disk Cleanup nor DISM cleans up those files after servicing.

Over time, you may end up with multiple copies of DISM servicing files in different subfolders under Temp.

dismhost servicing files fills up TEMP folder

Cleaning up “Temporary Files” in Disk Cleanup also may not help.

To fix the issue, do the following:



  1. Set the LastAccess registry value to 0. Please see the previous paragraph for more information.
  2. Run cleanmgr.exe as administrator. Running it as a standard user does not help.
  3. Enable “Temporary files” checkbox, and click OK.

    dismhost servicing files fills up TEMP folder - temporary files

That’s it. Disk Cleanup has now almost emptied your temporary directory. All those temporary DISM servicing folders have been cleared.

cleanmgr temporary files cleared

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

Editor’s note: I don’t use 3rd party cleanup and maintenance tools as I still rely on Disk Cleanup for this task. However, I 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. 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.

    Reply

Leave a Comment