How to clear the temp directory.
by Carl Farrington on Aug.21, 2008, under Computer Stuff, Tips & Tricks
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.
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
and press enter. This will change you into the Windows temp directory.
Then just like before, type:
rd /s .
All done! You can type “exit” to close the command prompt.
6 Comments for this entry
2 Trackbacks / Pingbacks for this entry
-
Publisher cannot complete the operation | Carl's Blog
August 25th, 2008 on 2:08 pm[...] Archives « How to clear the temp directory. [...]
-
Making Vim run Stata and clean up after itself | A Stata Mind
March 2nd, 2010 on 8:03 pm[...] this out, I also discovered that there's a quick way to clean up %temp% thoroughly, as shown here. Good to know. One of these days I might add that to _vimrc too. Now I'm on a roll. var [...]
October 27th, 2008 on 3:58 pm
ha ha, another useful article! I first saw one of my level one corporate help desk techies use this, exactly as you explained via explorer. i mimicked that same technique, getting stuck on the “in use” files.
i just tried this on my machine (windows xp professional), and it said “paramater format not correct – “s.”. i typed in rd /s. and then rd/s. and got the same message both times. did i miss something?
October 27th, 2008 on 5:54 pm
Hello Matt. You have to do:
rd[space]/s[space].
So that’s:
rd, space, slash-S, space, dot
I’ve updated the article to explain this a bit better.
November 6th, 2008 on 12:12 am
Thanks so much Carl for taking the time to lay it out for me. Worked like a charm. You’re the man!
Cheers,
Matt
May 15th, 2009 on 5:27 pm
thank u
it worked 4 me too
May 15th, 2009 on 5:27 pm
thank u
it worked 4 me too
July 15th, 2009 on 5:56 pm
AWESOME! I just recovered 3GB this way! Amazing. Thanks again!