Sunday, 10 May 2009

Emptying the temporary directories

One of the consistent problems with Windows XP seems to be the increasing size of the temp directory. I have dabbled with various vbscript scripts to empty the temp and temporary Internet directory when a user logs off but I've found it an ineffective approach; often not working at all.

What seems to work much better is relying on the underlying O/S commands to do it. Delete and Remove Directory are your friend. You can use the following batch file as a log off script for Active Directory or in the local policy on a stand alone machine.

@ECHO OFF
REM Empty user's temp directory of files and folders.
DEL /S /Q /F "%TEMP%\*.*"
FOR /D %%d IN ("%TEMP%\*.*") DO RD /S /Q "%%d"
REM Empty Window's temp directory
DEL /S /Q /F "C:\WINDOWS\Temp\*.*"
FOR /D %%d IN ("C:\WINDOWS\Temp\*.*") DO RD /S /Q "%%d"
REM If tmp and temp are different empty tmp as well
IF %temp% == %tmp% GOTO END
DEL /S /Q /F "%TMP%\*.*"
FOR /D %%d IN ("%TMP%\*.*") DO RD /S /Q "%%d"
:end

0 comments:

Post a Comment