Batch File to Cleanup Windows 2000, XP and Server 2003 User Profiles, Temp Folders, Internet Explorer Temporary Files

I’ve had this around for the longest time and figured I better put it here before I lose it forever to the dying Microsoft releases.

Note: This also cleans up VMware temporary files which build up over time. See this post for more information:  VMware Tray Dump Files Chewing up Space

Update: Added line to remove Temporary Internet Files directory/subdirectories also.

@echo off
setlocal
@for /d %%d in ( C:\Documents and Settings\* ) do @(
  echo %%d
  if exist %%d\Application Data\VMware (
    del /q %%d\Application Data\VMware\*.*
  )
  if exist %%d\Local Settings (
    if exist %%d\Local Settings\Temp (
      for /d %%e in ( %%d\Local Settings\Temp\* ) do @(
        attrib -R -A -S -H %%e\*.*
        rmdir %%e /s /q
      )
      if exist %%d\Local Settings\Temporary Internet Files (
        rmdir %%d\Local Settings\Temporary Internet Files /s /q
      )
      if exist %%d\Local Settings\Temp\*.* (
        attrib -R -A -S -H %%d\Local Settings\Temp\*.*
        del %%d\Local Settings\Temp\*.* /q
      )
    )
  )
)

Cleanup All Users' Temporary Files

This script simply cleans up all users’ temporary files and temporary internet files.
This works on Windows XP, Windows Server 2003.

@echo off
setlocal
@for /d %%d in ( "C:\Documents and Settings\*" ) do @(
echo %%d
if exist "%%d\Local Settings" (
if exist "%%d\Local Settings\Temp" (
for /d %%e in ( "%%d\Local Settings\Temp\*" ) do @(
attrib -R -A -S -H "%%e*.*"
rmdir "%%e" /s /q
)
if exist "%%d\Local Settings\Temp\*.*" (
attrib -R -A -S -H "%%d\Local Settings\Temp\*.*"
del "%%d\Local Settings\Temp\*.*" /q
)
)
)
)

Batch Script to Cleanup Temporary Files

This script is intended for use on Windows XP / Server 2003.

@echo off
setlocal
@for /d %%d in ( C:\Documents and Settings\* ) do @(
  echo %%d
  if exist %%d\Local Settings\ (
    if exist %%d\Local Settings\Temp (
      for /d %%e in ( %%d\Local Settings\Temp\* ) do @(
        attrib -R -A -S -H %%e\*.*
        rmdir %%e /s /q
      )
      if exist %%d\Local Settings\Temporary Internet Files (
        rmdir %%d\Local Settings\Temporary Internet Files /s /q
      )
      if exist %%d\Local Settings\Temp\*.* (
        attrib -R -A -S -H %%d\Local Settings\Temp\*.*
        del %%d\Local Settings\Temp\*.* /q
      )
    )
  )
)