Ask Leo!

Can I delete the contents of my TMP folder?

Home » Windows » Windows Performance

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:

Command Prompt showing delete of temporary files

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.

    " It's safest to delete temporary files using this technique when few, if any, programs are running."

    %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:

Article 11360 | Posted April 8, 2007

Recent Comments
0 Comments

ok I used the above cammand cd /d %TMP% and
rd /s to delete temp folder files and this is what i got ......access denied for 4 temp files that i wanted delete. They are..1. ~DF2F12.tmp.... 2.~DF30DF.tmp.... 3. ~DF969.tmp.... 4. ~DFA41.tmp. What are these temps? and how to get rid of them?

Posted by: Steve at May 11, 2007 11:20 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The are probably temporary files that are in use by a program running on your
machine - perhaps even windows itself. I get this all the time, and ignore it.

If you want to see what program has them open, that would be this article:
http://ask-leo.com/how_can_i_find_out_who_is_using_a_file_in_use.html

Leo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)

iD8DBQFGRNcOCMEe9B/8oqERAmBzAJ47nBMAjKl5BQkeG5hR2nkO8YLsHgCffxRc
DIdjXRQdXcAVBngjrmBGXhc=
=cVl/
-----END PGP SIGNATURE-----

Posted by: Leo A. Notenboom at May 11, 2007 1:50 PM

As a Senior sturggling to get into the 21st c's technology and having my home computer crash, YOU are the best tutorial I have known. Jacht van hel Geluk!

Posted by: Joop St Kloos at August 18, 2007 6:31 AM

Hi Leo,
can you please suggest a file that will recover dolby ac3 2channel decoding mpeg-2video,i always get this message when i try to burn a dvd.or could you please recommend a better burner than nero 7.
thank you in advance
meem

Posted by: meem at December 8, 2007 5:02 AM

I used to have Zonealarm and signed up with another anti-virus. Now I find it has left a lot behind which cannot be deleted. What to do?

Posted by: Celeste George at December 9, 2007 12:34 AM

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 AM

ok. 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
JYBEswOT0lXGAHfQHcMgLSs=
=J/MC
-----END PGP SIGNATURE-----

Posted by: Leo at June 23, 2008 8:24 PM

How do i clear or delete automatically my temporary files from my cache?

Posted by: John at July 30, 2008 2:35 PM

Does 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 PM

Post a comment on "Can I delete the contents of my TMP folder?":






(Email Address will not be published.)

Remember Me?

By popular demand...
my tip jar
Cuppa Joe
Buy Leo a Latte!

(you may use HTML tags for style)

New!

RSS feed Subscribe to the RSS Feed specifically for comments on this article.

Before commenting, please...

Please wait. Your comment is being processed ...


Ask Your Question:


ask-leo.com
Web

Stay Informed

Weekly Newsletter

Archives

By Category
By Date

Advertisers

Advertise on Ask Leo!

««   »»

Question? - Ask Leo!
Who is Leo?
Link to Leo!

Terms, Conditions & Privacy