Summary: Windows maintains a folder for temporary files but it doesn't always get cleaned up. With a little care you can delete the temporary folder's contents.
Apart from the temp files created, or used, by Internet Explorer, is it safe to delete any other temp files?
•
The short answer is yes, if you can. In fact, it might even be a good thing to do.
And it's also "safe" to delete the temporary files used by Internet Explorer, as long as you understand the ramifications.
•
Windows Temporary Folder
In a recent article I outlined how to discover and change the location of Windows temporary files.
Chances are if you go look at the contents of that folder, you'll see lots of random stuff including oddly named files and sub folders empty files and more. In fact if you've never cleared out your temporary files it's quite possible that there's a lot of stuff there, taking up lots of room.
And most of it doesn't need to be there. Much of the contents of your temporary folder is not only temporary, but stale. Unfortunately many programs fail to clean up properly when they shut down, and any program that crashed has no chance to clean up at all. The result is a temp folder full of "stuff".
"Stuff" you can get rid of.
You can easily use Windows Explorer to navigate to the TMP folder (see this article to determine the location of the TMP folder on your machine). Once there select all the files and then:
press delete to delete all the files.
If there's no error message, you're done.
If you get an error message indicating that a file could not be deleted because it's in use you have two choices after dismissing the error: either close the program that was using it and select all files again, or select all the remaining files except the one that is in use
Repeat until you get no errors, or the only files left are those in use
Yes, that's cumbersome. You'll quickly get frustrated by the number of files in use and the number of times you might have to repeat the process.
That's why I don't do it that way. I use the Windows Command Shell (which should be on All Programs, Accessories, Command Prompt). In the command prompt, I enter two commands:
cd /d %TMP%
rd /s .
Here's what it looks like in practice:

Let's look at each of those two commands in turn:
CD /D %TMP%
"CD" is the "Change Directory" command. ("Directory" is just another name for "Folder".) It says make the specified directory the current directory. "/D" means change the current drive if neccessary.
%TMP% is a reference to the TMP environment variable that we saw in that earlier article. It's a quick way to reference the temporary directory without having to know what it is.
When the CD command has completed, you can see that the current directory listed in the Prompt has changed to "C:\temp\sys" - that's the temporary directory on my machine; yours will most likely be different.
rd /s .
"RD" is the "Remove Directory" command. "/s" means "remove the specified directory, and all subdirectories it contains, and all the files too". So "RD /S" means delete everything in a directory.
"." means the current directory. So, RD then deletes the current directory and everything in it.
Except: we don't actually want to delete the current directory, we really only want to delete the contents of that directory. Not to worry: the current directory is "in use", by us. Since it's our current directory it can't be deleted. In fact, that's what that last error message in the example above is all about. "The process cannot access the file because it is being used by another process." is generated by the attempt to delete ".", which it cannot do.
And here's why this approach is much easier than the Windows Explorer approach: RD doesn't quit if there's an error. If it can't delete a file or directory it notes that in an error message, and then keeps on deleting the rest. In fact, you can see that there is one file in use above: ".\Perflib_Perfdata_1568.dat - The process cannot access the file because it is being used by another process." But all the other files and subdirectories that were in the TMP directory are now gone.
Like I said, things tend to accumulate in the TMP folder, so I do indeed periodically do exactly what I've outlined above.
Note: this technique relies on programs treating temporary files "correctly". By that I mean that if a program is going to rely on a temporary file, it needs to keep it open, which prevents us from deleting it. It's conceivable that program could not keep the file open and get confused when the temporary file it had just created disappeared for some reason. It's safest to delete temporary files using this technique when few, if any, programs are running.
Internet Explorer Temporary Internet Files
Nothing I've written about so far applies to Internet Explorer. It keeps its temporary files in a different location entirely. In IE 7 click on the Tools menu, Internet Options menu item, and in the Browsing history section click on Settings. In the resulting dialog you'll see Current location:, which will show you the current location of IE's Temporary Internet Files, also known as the "cache".
You can certainly delete the contents of the IE's cache; there's a button on the Internet Options dialog for exactly that. However your browsing experience may slow down as IE rebuilds the cache by downloading items from the web sites you visit frequently (items in the cache don't need to be downloaded each time you revisit the same page).
One warning for both.
Before you delete the contents of either your TMP folder or your Internet Explorer cache, you'll want to make sure you aren't keeping important documents in the temporary folder or cache by mistake. Typically one of the uses of either the TMP folder or the IE cache, depending on which mail program you might use, is to store attachments that you open. "Where did my edited attachment go?" outlines an issue where folks can lose data by mistakenly allowing important attachments to be saved in either of those locations.
Related:
Ask Leo! - How do I change the location of Windows temporary files?
Ask Leo! - Where did my edited attachment go?
Ask Leo! - What are those strange folders in my Temporary Internet Files?
Article C2989 - April 8, 2007
Trying to install Notepad++, and some other downloads like digsby IM.....
Now I Get this VISTA MESSAGE:
"Error writing temporary file. Make sure your temp folder is valid."
Deleted the files that would delete, used CCleaner - still, same problem.
HELP!
Jeff
Posted by: Jeff at May 18, 2008 12:38 AMok. so i deleted all my temporary files and now every time i turn my computer on two error messages appear telling me that windows cannot find the file and i cant get rid of those messages :( how do i do it?
Posted by: Humberto Garay at June 22, 2008 10:31 PM-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
That depends entirely on the specific files that Windows is
complaining about. My guess is you have references to
something now gone in your startup sequence.
Leo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
iD8DBQFIYGjNCMEe9B/8oqERAmRwAJ4jcjOsdyhbNeJ24CCyrwSYZWeRqgCfXmXl
Posted by: Leo at June 23, 2008 8:24 PMJYBEswOT0lXGAHfQHcMgLSs=
=J/MC
-----END PGP SIGNATURE-----
How do i clear or delete automatically my temporary files from my cache?
Posted by: John at July 30, 2008 2:35 PMDoes the article apply to Windows Vista? If not what is wrong with going to the windows folder openeing the tempaorary file and deleting all files in the temp folser?. Alsocan I do the same to the Windows Recent folder?
Posted by: William Weaver at September 14, 2008 3:04 PMMost of my KB is on temporary files. The command to delete these files concerna me. I have never deleted these files and am afraid of opening up a problem.....Thanks
Posted by: Martin Kaplan at December 16, 2008 10:42 AMDo i hit "enter" after i type in the "CD /D %TMP%" ? coz when i do i get "c:\DOCUME~1\allan\LOCALS~1\Temp>"
How do i put in the rd /s. ?
11-Feb-2009
I've followed the directions. the Command Prompt's last line is, "Are you sure? ? Y"
and then the next line is the flashing underscore type thing (_)
Is it deleting the files? It's not showing anything... The article didn't say anything about what it would show, and I'm fairly stupid.
Posted by: KT at April 3, 2009 1:59 PMdownload and install the free ccleaner it's safe and effective in cleaning temp and recycled files
Posted by: Mark Jacobs at June 12, 2009 4:19 AMOmg, thank you my computer has been running slow for a really long time. I thank you dude
=]how do i become a fan/member on your website?? please send me a link
Posted by: Amr Helaly at September 11, 2009 1:28 PM