Carl's blog

How to clear the temp directory.

by on Dec.11, 2010, under Computer Stuff

This is such a simple thing that nobody would ever consider writing a blog entry or howto about it, right? The thing is though, I frequently see IT support technicians using Windows Explorer, clicking through into the user’s temp folder, highlighting everything and attempting to delete. They are interrupted (and the process aborted) by a message stating that a particular file was in use and could not be deleted, so they de-select that one file, and try again. Some more files are deleted but once again they are interrupted and told that another file couldn’t be deleted. They de-select that file and try again. This can go on for ages..

Here’s how to do it properly.

Go to a command prompt (Start -> Run -> cmd [enter])

At the command prompt type:

cd %tmp%

and press enter. This will change you into the current user’s temp directory.

AT THIS POINT, PLEASE MAKE SURE THAT THE PROMPT HAS CHANGED TO THE TEMP DIRECTORY. IF THERE IS ANY KIND OF ERROR, OR THE PROMPT DOESN’T CHANGE, DO NOT CONTINUE ON WITH THE NEXT COMMAND. I DO NOT WANT YOU TO REMOVE THE WRONG DIRECTORY!

Then type:

rd /s .

(that’s rd space slash-S space dot)

then press enter. Don’t forget the . at the end. This means “remove the current directory and all subdirectories, including all files.”

What will happen is that the contents of the temp directory and all subdirectories will be removed, but not the temp directory itself, because you are currently working in that directory (via the CD command) and therefore it can’t be deleted.

You’ll receive access denied messages for all in-use files, plus the temp directory itself. That’s fine. Those access denied messages would have been showstoppers if you were using Windows Explorer.

The above is clearing out the current user’s temp directory, which is located within that user’s profile directory (Documents and Settings\username). To clear out the system temp directory, which is located under the Windows directory, type:

cd %windir%\temp

(that’s CD, space, %windir%\temp)
and press enter. This will change you into the Windows temp directory.

AT THIS POINT, PLEASE MAKE SURE THAT THE PROMPT HAS CHANGED TO THE TEMP DIRECTORY. IF THERE IS ANY KIND OF ERROR, OR THE PROMPT DOESN’T CHANGE, DO NOT CONTINUE ON WITH THE NEXT COMMAND. I DO NOT WANT YOU TO REMOVE THE WRONG DIRECTORY!

Then just like before, type:

rd /s .

All done! You can type “exit” to close the command prompt.


6 Comments for this entry

  • Mike Renna

    Frustrating that we have to do this. and this doesn’t deal with the temp folder for other users….

    and something I’ve run into loads of times recently is that the content.ie5 folder is hidden even when I say to show hidden and system folders! I click my way to
    c:\docs & settings\user\local settings\temporary internet files and then add \content.ie5 press enter and see loads of folders! then I can delete them. disc cleanup, ccleaner, etc. don’t seem to want to delete this folder. why is it so hidden and with your rd /s work there? But I don’t want to delete cookies ’cause some have passwords I don’t want to re-enter. sometimes they are in user\cookies and other times they are in temp internet files.

    all this is for xp, I am not sure if the problems are the same with 7

  • Carl

    Hi Mike. I had previously (before I lost/wiped out my blog and all its comments!) mentioned something about the “temporary internet files” directory, and that is that you mustn’t clear out the Temporary Internet Files directory itself, because Outlook has a directory in there for the temporary storage of attachments, and removal of that directory will break the display of inline images that are embedded within multi-part messages.

    So, I would normally do:
    cd %userprofile% [enter]
    cd loc [tab] \ tempo [tab] \ cont [tab]

    and let the auto-completion do the above, and then do the “rd /s .” from within the Content.IE5 directory.

  • James

    Hello,

    In XP Pro I just did the cd %windir%\temp and it’s deleted the whole /My Documents folder and everything in it. Please tell me there’s a way I can reverse this?

    Thanks.

    • T

      same thing here, finally found how to fix error message that I was receiving using autoruns…not this way… lost all in My Documents…lost portions of Outlook archive folders too…real pain…wish I read all the comments before trying this…

  • Carl

    You guys must have failed at the CD part, and then continued on with the “rd / .” after failing to change directory. So you removed the directory that you started off in.
    I will add information above to tell people to ensure they have correctly changed directory before carrying on with the remove-directory command.
    Sorry.

  • Christina

    THANKS!

    This type of post that “is such a simple thing that nobody would ever consider writing a blog entry or howto about it” is EXACTLY what high heel wearing, nail polish sporting girls like me need!

    Done, all on my own (without the help of an I-can’t-believe-you’re-asking-help-with-that IT guy)! Score!

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...