Here's a little script I wrote that I keep on my USB utility drive... GREAT for citrix servers :)
@echo off
Echo Started %time%
Echo Started %time% >> temps.txt
Echo Running for XP... >> temps.txt
Echo Running for XP...
FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO IF EXIST "%%G\Local Settings\Temp\" (
RMDIR /S /Q "%%G\Local Settings\Temp"
MKDIR "%%G\Local Settings\Temp"
Echo Cleared %%G\Local Settings\Temp
Echo Cleared %%G\Local Settings\Temp >> temps.txt
)
FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO IF EXIST "%%G\Local Settings\Temporary Internet Files\" (
RMDIR /S /Q "%%G\Local Settings\Temporary Internet Files\"
MKDIR "%%G\Local Settings\Temporary Internet Files\"
Echo Cleared %%G\Local Settings\Temporary Internet Files\
Echo Cleared %%G\Local Settings\Temporary Internet Files\ >> temps.txt
)
Echo Done.
Echo Running for Vista >> temps.txt
Echo Running for Vista...
FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO IF EXIST "%%G\AppData\Local\Temp\" (
RMDIR /S /Q "%%G\AppData\Local\Temp\"
MKDIR "%%G\AppData\Local\Temp\"
Echo Cleared %%G\AppData\Local\Temp\
Echo Cleared %%G\AppData\Local\Temp\ >> temps.txt
)
FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO IF EXIST "%%G\AppData\Local\Microsoft\Windows\Temporary Internet Files\" (
RMDIR /S /Q "%%G\AppData\Local\Microsoft\Windows\Temporary Internet Files\"
MKDIR "%%G\AppData\Local\Microsoft\Windows\Temporary Internet Files\"
Echo Cleared %%G\Local Settings\Temporary Internet Files\
Echo Cleared %%G\Local Settings\Temporary Internet Files\ >> temps.txt
)
Echo Done.
Echo Ended %time%
Echo Ended %time% >> temps.txt
Use at your own risk, etc... THIS DELETES STUFF.
I run this from the Documents and Settings folder or Users on Vista. You could easily throw a CD command up top to run this from anywhere you want.
cd %userprofile%
cd ..
Also, it's generally safe to clear the temp folder at any time in my experience. Programs using files in temp will lock them, and this script will error on that file and keep going.
The IF EXIST line is particularly nice here, it keeps the script from creating folders in NetworkService and similar folders, and if you aren't running it on Vista or XP that section goes by super fast.
Creates temps.txt logfile where ever you run the script from
Edit: Advice from ##windows-server on Freenode:
Q: Why don't you detect which OS it's running on in the begining and run the appropriate section?
A: I use the script frequently on offline media, such as a hard drive that's been extracted.
Instead of mapping to the network drive "H:\", use the full UNC path:
i.e. "\\server\user\docs"
This worked for me when I ran into the same issue~
Best Answer
so my final version looks like this:
where the character between delims= and the following " is a single tab. Make sure your editor emits a tab and not spaces.
EDIT: On Windows 7 (and maybe all windows) you shouldn't specify delims= at all as it defaults to which is the whitespace used inbetween the tokens and not just a tab.