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:
- Files with Read-Only, System, or Hidden attributes
- Files which have been accessed in the last seven days
- 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.
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.
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.
Cleaning up “Temporary Files” in Disk Cleanup also may not help.
To fix the issue, do the following:
- Set the LastAccess registry value to 0. Please see the previous paragraph for more information.
- Run cleanmgr.exe as administrator. Running it as a standard user does not help.
- Enable “Temporary files” checkbox, and click OK.
That’s it. Disk Cleanup has now almost emptied your temporary directory. All those temporary DISM servicing folders have been 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.
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.
The temporary files are all gone, except the in-use files and folders.
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!
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.
wow bro thank you a lot i learnt sth new today 😀