[Note: An earlier version of this tip had some inaccuracies which were brought to my attention. Thanks to Ed Bott for his keen eye!]
[Note #2: Ed's published a blog entry about this issue, and some additional notes that are well worth reading -- including a super-useful link to a tip on how to customize the way the Disk Cleanup tool runs.]
This is actually not an indictment of Vista alone, but something I've seen in Windows for quite some time now: the user profile \TEMP directory. It fills up with the most amazing amount of trash imaginable, and over time it can cause programs to malfunction left and right in ways that defy analysis.
Vista does have a way to deal with it: the Disk Cleanup tool. which purges the \TEMP directory on demand. However, as a safety measure, it doesn't delete anything newer than one week -- for instance, temporary files created as part of a program's installation process.
If you want to manually purge the \TEMP directory without the date cutoff restriction -- just blast everything in there -- here's one way to do it. Copy the following into a text file with a .BAT extension:
rd /s /q "%localappdata%\temp" && md "%localappdata%\temp"
(That's all one line, by the way.)
When run, it'll erase the entire contents of the TEMP directory and then recreate it anew.
Two caveats:
- If there are any files that are in use in the directory, they will not be deleted.
- As hinted above, do not run this command when you're in the process of installing software, such as before a reboot to finalize a program installation. It may delete components of the installer that are needed after the reboot. (Note that if you attempted to install a program and the installer failed and left garbage in the \TEMP directory, it might not be a bad idea to purge all of that before attempting to re-run the installation. Just make sure the installer is not actually running before attempting this!)

This works for the user that is currently logged on the system only.
As the string "%localappdata%\temp" points to current user's:
[system drive]:\users\[username]\Appdata\local\temp
I have the problem right now but with my son's "restricted" account... Vista makes it even worse and it is a flaw in the system setup.
Restricted account users can only "Read" or Write" but cannot modify, hence they cannot delete or overwrite.
After about 7 months of running Vista and due to a trojan I found and removed with AVG, I decided to do a full system scan yesterday.
To my surprise, after 10+ hrs it did not finish and it was still in my son's "user\appdata\local\temp" directory.
Finding the directory's info through explorer, (took nearly 10 minutes to collect data), I was stumpped with over 517,000 files, 22 directories and nearly 47 GB in size !!!!
And this is only after only 7 months.
In contrast my "user\appdata\local\temp" directory had only 12,000+ files and only 980 MB. (which makes sense...)
Because restricted users cannot delete, the "\temp" directory will continue to grow at 1000's of files per day until it chockes your drive.
Explorer cannot delete these files becasue it crashes instantly upon pressing the "del" key. It seems it cannot spool the list of files to delete and just dies.
I resorted to good'ol DOS to just delete the files without deleteing the directory. The following command would apply to all users (including the one currently logged on) without having to delete the "\temp" directory:
cd [system disk]:\Users\[username]\AppData\Local\temp
At the prompt type:
del *.* /s /f /q
Where:
*.* will be all files
/s will include all subdirectories
/f will force to include all read only files
/q will set it to quiet mode without prompting for confirmation.
You can automate this in a batch file if you need to and run it in the scheduler from the administrator side for all "restricted users".
Some nice reading ;)
I deleted the files in my vista TEMP directory which saved me 20gig of HDD space.
My virus scans now scan alot faster too.
What about the c:\windows\temp?
does all this apply to? i went to alot of sites, they all say the user/appdata/temp but no1 ever mentions about the windows\temp
Hello,
Anyone knows why the temporary internet files do not show immediatly in vista? instead, i wait for about 20 minutes and revisit the folder to find the new files.. any idea please?