Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

Can I delete the contents of my TMP folder?

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.

Become a Patron of Ask Leo! and go ad-free!

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 necessary.

    ” 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.

Subscribe to Confident Computing! Tech problem solving & safety tips & a weekly confidence boost in your inbox every week.

I'll see you there!

10 Reasons Your Computer is Slow

Slow Computer?

Speed up with my special report: 10 Reasons Your Computer is Slow, now updated for Windows 10.

NOW: name your own price! You decide how much to pay -- and yes, that means you can get this report completely free if you so choose. Get your copy now!

25 comments on “Can I delete the contents of my TMP folder?”

  1. Given your recent article on changing the location of temp files, I would suggest that the first command be

    CD /D %TMP%

    instead. The

    /D

    flag tells the command to change the current drive as well, if needed.

    For example, if

    TMP

    were set to

    D:\TEMP

    , your example would leave you in the same directory on

    C:

    , but the

    /D

    flag would switch you to

    D:

    as well.

    Reply
  2. —–BEGIN PGP SIGNED MESSAGE—–
    Hash: SHA1

    An excellent thought. I’ve updated the article to reflect that.

    Thank you!

    Leo
    —–BEGIN PGP SIGNATURE—–
    Version: GnuPG v1.4.6 (MingW32)

    iD8DBQFGGmHVCMEe9B/8oqERAt8OAJwJbzg/Hh8vCi3InqyPvMun/AdqPQCbBkUq
    38198xZzpUCvvBtFrTTUTWs=
    =i1Og
    —–END PGP SIGNATURE—–

    Reply
  3. Ummm…. many many moons ago, I thought it was okay to clear the temp folder and erased my boss’s calendar. I’m not sure if this was a stupid software design decision or another idiot temporary employee who thought the “temp” folder is where the “temp” should put files.

    Either way, you might want to sort files by date, then only delete things over a week or two old, just to be safe.

    Reply
  4. 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?

    Reply
  5. —–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—–

    Reply
  6. 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!

    Reply
  7. 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

    Reply
  8. 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?

    Reply
  9. 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

    Reply
  10. 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?

    Reply
  11. —–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—–

    Reply
  12. 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?

    Reply
  13. Most 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

    Reply
  14. Do 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. ?

    Yes, type “CD /D %TMP% followed by Enter, and then “rd /s .” followed by enter. Note that there is a space between “/s” and “.”.

    – Leo
    11-Feb-2009
    Reply
  15. 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.

    Reply
  16. 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

    Reply
  17. 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….

    Reply
  18. Tried everything still can’t delete file.File folder content is 0.When I try to delete get error message..can’t read from source or disk???

    Reply
  19. Hi!
    I use ccleaner, Advanced Windows Care and I have manually tried to clean up my Temporary Internet Files but my PC shuts down immediately when I start the process. What is wrong with it?

    Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.