Ask Leo! by Leo A. Notenboom

Can I delete the contents of my TMP folder?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

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:

Helpful? Get new articles weekly by email in my FREE newsletter!

Your Name:
Your Email:


Why Subscribe?

Article C2989 - April 8, 2007

Was this article helpful? «Yes» «No»

Recent Comments
21 Comments

download 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 AM

Omg, 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

can i delete all the contents of my temp file on vista by going to the temp file opening it highliting all contects and deleting.
Also i have the ccleaner when i clean the registry is there anything i shouldnt delete
thanks....

Posted by: Ashley at January 14, 2010 4:16 AM

A good free program to address this and lots of other issues is Advanced System Care -- at http://www.iobit.com. I use it every 2 weeks and my system runs amazingly well.

Posted by: digitrunner at January 20, 2010 2:29 AM

Have a look here: http://lisati.myftp.org/page2

Posted by: Lisati at January 24, 2010 4:22 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)

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

Before commenting, please...

  • Read the article at the top of this page. If your comment shows you didn't, it'll be deleted and ignored.

  • Comment only on this article. Use the Google search box at the top of the page if you have a question about something else.

  • Don't include personal information in the comment. No email addresses. No phone numbers. No physical addresses.

  • Don't spam. Excessive links to unrelated sites within a comment or across multiple comments will cause all such comments to be removed.

  • Don't ask me to recover lost passwords or hacked accounts. I can't, and those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...


Question? Ask Leo!