Software

How do I... Force Disk Cleanup to delete all temporary files?

You may have found that Microsoft Windows XP's Disk Cleanup utility misses a spot from time to time, retaining temporary files most recently accessed. Here's how to perform a clean sweep of your Windows XP files by forcing Disk Cleanup to get rid of all your temporary files.

If you've ever run the Microsoft Windows XP's Disk Cleanup utility, you probably discovered that your temporary files occupy a significant amount of space. You might select the Temporary Files check box in order to allow the Disk Cleanup utility to delete the files in the Temp folder, but the Disk Cleanup utility will not remove all the files. The reason for this oddity is that the configuration for the Disk Cleanup utility does not allow deletion of files accessed in the last seven days.

Alter the parameters

By altering the LastAccess value in the registry, you can configure the Disk Cleanup utility to delete all the files in the Temp folder regardless of the last accessed date. Here's how:

  1. Launch the Registry Editor (Regedit.exe).
  2. Go to
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\
    Explorer\VolumeCaches\Temporary Files
  3. Locate and double-click the LastAccess value.
  4. When you see the Edit DWORD Value dialog box, change the Value Data setting from 7 to 0 and click OK.
  5. To complete the operation, close the Registry Editor and restart Windows XP.

Changing the value to 0 will force the Disk Cleanup utility to delete all the files in the Temp folder every time you select the Temporary Files check box.

Notes: Since editing the registry is risky, be sure you have a verified backup before saving any changes. This tip applies to both Windows XP Home and Windows XP Professional.

Miss a tip?

Check out the Windows XP archive and catch up on our most recent Windows XP tips.

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

56 comments
alashhar
alashhar

thank you for this tip, it is helpful

s31064
s31064

When I get a loaner laptop back I have to clean it up for the next project. There are times that several users have logged in and therefore created multiple profiles all with their own temp directories. How can I get disc cleanup to clean out all users' temp (and ie temp) directories?

JandNL
JandNL

Under Windows, there is only a folder titled Browser, no Volume anything. Where else should we look? We run searches for *.bak, *.log, *.tmp, *.wbk, and ~*.*, along with folders log, recent, and temp, fairly often, but it's very time-consuming and therefore inconvenient.

droach
droach

Is there a way to force Disk Cleanup to delete files in other temp folders, such as C:\TEMP, and C:\WINDOWS\Temp? It seems these folders are either skipped or they are not emptying out based on the 'Last Access' registry value.

deyamag
deyamag

Thank U very much, new datum.

normhaga
normhaga

HKLM/software/microsoft/currentversion/explorer/volumecaches/temporaryfiles/ set the Dword lastaccess = 0. Now you can use the regular windows disk cleanup to clear all temporary files. The default setting is 30 days. With this hack, the setting is 0 days.

husserl
husserl

...or 'command prompt here' del*.*/use windows explorer, or use Stephen Gould's cleanup, which checks everything on all drives. It deletes protected temporary files during the reboot process. According to it I have deleted 23.4 Gb in this incarnation of windows.

pmat20
pmat20

I had been using this free utility for a few years and it seems to be doing the job of cleaning up all unwanted and temp files. Anyone else out there using it?

Mick Barker Sr.
Mick Barker Sr.

Here's a bat file that can clean temp files that the clean up wizard misses too. Open Notepad paste this line = del /s /q "C:\Documents and Settings\yourname\Local Settings\Temp\*.*" Replace yourname with the name of the account you've logged into and adjust the drive letter or path as needed. Save the file with a .cmd or .bat extension (for example, killtemp.bat) and put the file or a shortcut to it in your Startup group (Start, All Programs, Startup). This way, it will run each time you log in to your Windows account.

michael1r
michael1r

Strangely that key doesn't exixt in My XP with complete updated SP2. Iwas going to try it.

ajmm45
ajmm45

I am gonna try that and see how it goes....Thank you

dkowal
dkowal

Q - Is it 'safe' to implement this as is? Reason asked is that (I'll assume) MS put the 7 day 'limit' in there for a reason. Please clarify - clicking the Temporary files checkbox, removes all but the last 7 days worth of these files? What real harm does it do to keep the 7 days as is? DK

mjlas01
mjlas01

Nice tip, something to help me tweak Windows further.

WoW > Work
WoW > Work

Been using CCleaner now for a while, one of the best system cleanup programs I've ever used. Startup and Program cleanup, registry entry cleanup, etc. Price is just right too: free.

dgudek
dgudek

I use the schedule tasks to clear temp files, TIF, etc.. This reg tweak will make my tasks more useful. Thanks. I found a pretty neat How-To that shows you how to schedule the task to run and NOT prompt the user for "What would you like to clean?". You set what you'd like to clean once, plug in credentials and your golden. ---------------------------------- http://tweakhound.com/xp/tasks/sch_disk_cln.htm

bkoelrich
bkoelrich

Is it true that, after installing any new software/programs, and/or reinstalling Windows O.S. from scratch, the temporary files should NOT be deleted for the first week thereafter, or else what you've installed may become de-stabilized? Or, can they be deleted immediately?

narayana_murthy
narayana_murthy

Disk Cleaner is a free open source tool to quickly and easily clean your hard disk from temporary files like those in the system temporary folder, the Internet Explorer Cache and Cookies folder, and the Recycle Bin. Disk Cleaner is absolutely free from adware and spyware.

BALTHOR
BALTHOR

If you take out the 'hide' in 'folder options--view' and click in 'show hidden files and folders' you'll see them in C:\,C:\Documents and Settings\WIN XP\Local Settings\Temp,C:\WINDOWS\Temp.

rbates
rbates

I have been using a slightly different approach to eliminating temporary files upon session login. I have a copy of the old DELTREE.exe DOS file that I copy into the c:\windows\system32 folder [XP]. Next I create a simple batch file [clean.bat] which I keep in a c:\batch folder. clean.bat-------------- deltree /y "%userprofile%\Local Settings\Temporary Internet Files" deltree /y C:\WINDOWS\Temp md C:\WINDOWS\Temp deltree /y %temp% md %temp% --------------end of Clean.bat The /y switch gives DELTREE permission to perform the action, without asking you if it's OK. I save this file, and then create a Scheduled task that runs at logon, calling the clean.bat file. I support more than a 100 PC's, and this eliminates many tech support calls! Some installation's save files in the TEMP folder, and after reboot looks for these files. If you find yourself having installation problems, disable the Scheduled task, temporarily until the installation is successful.

mikehigdon
mikehigdon

In this instance, delprof.exe would be a great tool for you. If you search google it should be the first choice. This tool will delete user profiles including there temp directories. FYI.

normhaga
normhaga

In the case of the last access value, the reg edit works for 2k, XP, and Vista. Not all reg edit do work for Vista though.

normhaga
normhaga

If you do not google registy edits/tweaks then no, if you do, then yes. Knowing a thing should lead to questions about it. Wanting to know more about it leads to research, research leads to answers. Google can be a good or bad tool. But you have to ask it.

JCitizen
JCitizen

but I already got the best in my book; CCleaner does more than just cleanup all the same files; and it's dead bang reliable. If something wasn't right after a reg cleanup, it can be easily fixed with the backup. Which never happens; I just tested it to find out if it does work and it does -swimingly so. Oddly enough, no one has bothered to write a review of BeClean after more than 12,000 downloads! Perhaps you could do the community a favor and be the first to write one!

ajmm45
ajmm45

I was told the new explorer windows (I have windows XP) has a lot of problems,is that true or should I just keep up dating the newest version?

saghaulor
saghaulor

I use CCleaner too. It's a nice tool for what its worth. But I've noticed that it doesn't clean everything from the temp folder.

wesley.chin
wesley.chin

That is good and something I have done on my personal machine. But issues that might arise if the temp directory has potentially useful data. But of course even after deletion, there are recovery methods.

JandNL
JandNL

We posted a question several weeks ago because the recommended process did not work for us. Nobody replied. Currently, we use a combination of VCom/Avanquest Fix-It Utilities, CCleaner, EasyCleaner, and going through a search for *.bak, *.log, *.tmp, *.wbk, and ~*.*, plus going through all log, recent and temp files. Is there a more efficient method that cleans out all the garbage? We use Windows XP SP3 on our primary computer and a laptop; the other laptop has Vista; we also have a Mac Mini with OS X.

ahilliard
ahilliard

How would you get a hold of this? I am not a programmer per se but I am a little familiar with DOS.

4rd4fun
4rd4fun

I really like the deltree idea- would not have thought of that one. We have had fairly good success with ccleaner - I think that is polically correct for crap cleaner? it is a freeware

menglund
menglund

If this is a bat file should it not be run under "comand" How did you put this in your log on?

radio1
radio1

rbates' batch file can be implemented in Windows (XP for sure) without the use of the old DOS executable 'deltree.exe', by instead CAREFULLY substituting the 'rd' command. For many versions of Windows (I think going back to NT) the 'rd' command has supported the /S and /Q parameters -- to see if yours does type "rd /?" at a command prompt. Here is an example of two ways of deleting all files and folders in C:\WINDOWS\Temp: ** DELTREE METHOD: deltree /y C:\WINDOWS\Temp ** CD/RD METHOD (2 lines): cd /d C:\WINDOWS\Temp rd /s /q . Note the space between the q and the period. Note also that the above CD/RD method will always output an "error" message as the command tries to actually remove the Temp folder itself (in addition to all the content below it), but fails because our own batch file is currently accessing it due to the CD command above. We're exploiting this to achieve the behaviour we want. I don't actually recall if the old deltree.exe program actually removed the top-most folder specified or not. Hope this is useful to someone. Cheers All.

armstrongb
armstrongb

That bat file is a smart and easy way to help end users and reduce one's work load. Good article as well, I always learn something new every week. Thanks.

macoy321
macoy321

Nicely done rbates... I will try it at home.

dprows
dprows

I would assume you mean Internet Explorer. I use IE 7 and think it is nice. I like it much more than 6 and lower. I haven't had any issues with it. There are some things (like with all software) that I do not like, but it is nicer than the old ones. I really like being able to have multiple home pages. I am sure that someone will know all of the downsides to having it, but there are also many downsides to IE 6.

bkoelrich
bkoelrich

I've recently installed Ccleaner and, once I determined which cookies I wanted to save, I now run Ccleaner after every PC session: for after internet surfing, to clean my installed applications, and to clean any rouge registry entries. Ccleaner also specifically says that it will not clean any temporary files created newer than 48 hours ago (although I think you can change this setting). I also have "Diskeeper" defragmenter installed in place of the poor-quality Windows O.S. defragmenter, and keep my disk defragged, as well as make sure my paging file and MFT are both defragged and have adequate disk/memory space so they don't become fragmented in the future. These operations are all available and automated in Diskeeper - a terrific program that keeps your PC running fast and smoothly, along with Ccleaner. I also have "RegCleaner" by Macecraft Software that effectively finds "orphaned" registry entries over-and-above Ccleaner, and allows you to simply place a check in the box next to whatever entries you want to remove (like from deleted programs) and just leave unchecked what you don't, as well as either make a backup that it saves for you, or not - your choice. If you want that program, once installed, it'll open instead of the Windows O.S. defragmenter, and do a much better job! It's a pay program (sorry, but well worth the money!). Go to "www.macecraft.com" for the newest version. I've also discovered the "help" feature in Windows "regedit" that's really a registry search utility. As with all registry cleaning, anything you choose to delete must be done with care, but I've found that, as long as I only ask this regedit feature to search for specific program/software names, as well as their publishers, which I want to remove, I've found leftovers from deleted programs that I've been able to successfully remove without causing any problems, that RegCleaner or Ccleaner missed. If you have any trouble after doing any registry cleaning, you can always click on "Start", "Run", and type "sfc[space]/scannow", put your Windows O.S. reinstallation CD-ROM disk in your optical drive, exit out of the auto-play install/setup window, click "OK" in the "Run" window, and the "scannow" utility will make sure all your Windows secure & protected files & folders are intact and in their original condition, and will pull what it needs from the CD-ROM if it finds anything that's corrupted or missing (this process should be run anytime you experience system de-stabilization, or 6 months goes by, just as a maintenance operation, especially if you install and delete a lot of stuff). Also, provided you have the installation CD-ROM's for any other programs that may be affected by cleaning the registry, you can always run the "repair" feature in their auto-play installation/setup utilities to make sure they aren't compromised. Of course, you can always re-install any affected software from their respective websites, too. So, registry cleaning doesn't have to be as dangerous as some make it sound, but you do need to make sure you know the names/publishers of all the software you have installed. This is easy to do by making note of what you have by simply opening "Add/Remove Programs" in "Control Panel", checking the "show all updates" checkbox at the top of the add/remove window, and noting the names (and often the version no.s) displayed of what you have installed. You can also right-click on each installed program to get tech info that oftentimes includes the publisher's name, version no.'s, and their websites. Also, if you go to the folder in which you installed any given program (e.g., "Program Files", "WINDOWS"), scroll down to find its ".exe" file, right click on it, and select "properties", most applications will open up a tabbed window that offers publisher/version #, etc., info about them. If an entry is too cryptic to know what it's for, it's an arduous process, but if you want to make sure you don't delete the wrong things, it's worth your while to right click on such files anyway, and see if they tell you what publisher/software they're associated with. Sometimes, this information does not come up, so I leave those entires for automated cleaning programs to deal with, like Ccleaner, RegCleaner, and the search feature in regedit. Also, if you don't know where a particular program has been installed on your PC, clicking on "Start", "Search", "Files and Folders" and just typing in as much of any software's/program's name as necessary to make sure to find only entires related to it, your search will yield results showing all the file paths where various parts of the software have been installed on your PC. Just delete them right inside the search window; or jot down the path, find the files/folders by navigating to them, and delete them manually, each by right-clicking on the file/folder, and selecting "delete". If you go into "Folder Options" in Control Panel, and uncheck "Hide system files(folders)", and uncheck any other boxes that hide secure/protected files so they'll be displayed, your search results will show you everything, and you'll be able to remove as many entires from a deleted program as the Windows search utiility can display. So, armed with this info., as long as you only clean registry enties in regedit for those programs you've uninstalled using Control Panel's "add/remove", Windows "Search" utilty, Ccleaner, and RegCleaner, you'll discover that many programs leave "leftovers" all over your PC after you thought you had over-written deleted programs completely. Some of these leftovers can affect, and even cause problems with, the way programs/software you retain operate. So, it pays to educate yourself as to how to clean your PC thoroughly. Use the "Help" feature in your various software applications, and in Windows/Microsoft's website, as well as any software/hardware tech support people you both trust and can afford, when you need help. You can also do a "Google" or other internet search on any entry/application, etc., and read about it from articles on the internet that may help keep you from deleting something you discover you want/need, and to educate yourself about what's on your PC. Microsoft will take ownership and correct problems with anything having to do with their software/applicatins/O.S. if you go to their website and click on "support" and then scroll down to "ask a question". A page will open with an email form in which you can describe your problem and enter your email address/phone #, and request tech support, and they will work with you for free - even if you have an OEM version of their O.S. As long as it's a bug/problem that's their fault, and causes problems for you, they'll even connect remotely to your PC, as well as call you back to schedule troubleshooting/"repair" sessions, until they've corrected the issue. Even if they can't fix it right away, they enter the problem into their software engineering/updates/hotfix "to-be-fixed" list to resolve it once they've had time to fully troubleshoot/research it, and find a way to correct it. Some purists actually backup their data, emails, address books, etc., after cleaning them with anti-virus, anti-malware, etc., programs, either to a CD/DVD-R/RW, or a USB-connected backup hard drive. Then, they completely wipe their internal "C" hard drives of everything - the O.S. and all software. They then re-install their O.S. from their re-installation CD-ROM's/Microsoft Updates site, and re-install their software applications from the CD-ROM's or websites they came from, to get "fresh" and updated versions, and then re-install their backed-up files/data they saved before wiping their hard drive, to make sure there's nothing on their PC except what they absolutely know they want - all in clean (hopefully) and new versions (if applicable). Some people are up to doing this operation every 6 months or so, others never do it. I save such a drastic oparation only for issues that cannot be resolved in any other way. Meanwhile, I have a USB-connected backup drive that's the same size in GB's as my internal "C" hard drive, and run fresh backups of my data, "My Documents" folder contents, emails, and email address book - after running all of these through my PC cleaning programs/utilities - just in case my internal hard drive crashes, or I really do have to completely wipe my "C" drive and reinstall everything from scratch to correct an otherwise unfixable problem. All of this may sound like a lot, but once you take the time to "play" with these applications/utilities by opening add/remove programs, the "Program Files" & "WINDOWS" folders, run searches if you can't find something, etc., and get to know what's on your PC that you want, and what may have been dumped on it by your PC manufacturer that's just taking up space and can be deleted, you'll learn how to keep your PC clean, lean and running smoothly and fast.

candmrandd2
candmrandd2

I care for 6 computers used by non computer over 60 users in my neighborhood. Before installing CCleaner I would get calls ever day. After install and telling them to run program at shutdown. I now get a call about 1 a week. this is one great free program.

techrep
techrep

This file is part of Windows98 and maybe Win95 too.

The Scummy One
The Scummy One

Here is my .bat file del /f /s /Q "%userprofile%\local settings\temp\" del /f /s /Q "%systemroot%\temp\" del /f /s /Q c:\temp del /f /s /q "%systemroot%\prefetch\"

husserl
husserl

IE7 seems to have to 'think' for ages before opening a new page. I use the very excellent Maxthon, which doesn't, and has a few useful extras bolted on.

JCitizen
JCitizen

industry wide. Macecraft put all their quality into the product and didn't waste money on the GUI consol. It may look a little plain, but WHAM! BAM! and you can chase a lot of snakes out of the registry. It is the only registry cleaner I've found that can fully clean Symantec outta your computer! Even though it is paid software; gee wiz I'd say $16 bucks is pretty good for a [b]LIFETIME[/b] license!!!!

JCitizen
JCitizen

and you have more control than the work around in this article. Good article non the less.

The Scummy One
The Scummy One

and/or manual run depending on the person to use it. Hence the 'prefetch' folder addition. temp IE files are deleted more often (here) than this script runs. So, I had no real reason to add it myself. :) Thanks for the info! I hadnt even thought about it in a long, long time

Understaffed
Understaffed

Here's how mine looks presently: del /f /s /Q "%userprofile%\local settings\temp\" del /f /s /Q "%userprofile%\local settings\temporary internet files\" del /f /s /Q "%systemroot%\temp\" del /f /s /Q c:\temp del /f /s /q "%systemroot%\prefetch\" I placed it with Group Policy in an OU that is just below me, so that it will apply to all company users except network admins- so it shouldn't break any software installs that keep the info through a reboot. Is there a reason you didn't add temp. internet files to your script?

The Scummy One
The Scummy One

it slows down the boot process for the first few boots or a single boot, and not by that much. After that/those boots, it speeds up the boot process. This is because everytime you open an app (even if it is just once) it loads a small portion into the boot process, so it IS a good idea to clean it out periodically. Removing temps isnt an everyday thing for most systems, so adding the cleaning of the prefetch is not a bad idea at all.

husserl
husserl

There is a problem with deleting prefetch files. It slows down the boot process for one thing, never mind the speed of application execution when already logged on. I use cleanup, free from http://cleanup.stevengould.org/ and have instructed it to leave them alone, and this seems to have been a smart move. It creates a registry entry, to enable it to finish tidying up those protected files during the boot process. Make sure that you specify which temporary files it's not allowed to break; stuff from Advanced Zip password recovery should not be deleted, clearly!

dbreuer
dbreuer

This takes care of installation problems del %temp%\?*.* /a-a /s >nul attrib -a %temp%\?*.* /s

khward
khward

For those that really do not want to make changes to the registry try downloading the above free program. It not only removes temporary files it performs many other "disk cleanup" functions at the same time.

wim.hoogstraaten
wim.hoogstraaten

Thanks very much for this excellent little tool! W.M. Hoogstraaten The Netherlands

armstrongb
armstrongb

That prefetch folder can get pretty crowded and most people have no idea that it even exists. Thanks for the excellent bat file, it will be useful to me and I will share it with my buddies at work.

Editor's Picks