The below script will remove temporary internet files and temp files from user profiles located on a Windows PC or server.
Copy the below code and rename with a .bat extension. e.g. remove.bat
Please test on a PC before providing to a live environment.
REM @echo off
REM – This script searches through profiles and removes temporary internet files and temp files.
set HDRIVE=c:
set HPATH=Documents and Settings
%HDRIVE%
cd \%HPATH%
REM – This line sets up the loop for the script
for /d %%i in (*) do call :ifthen %%i
goto end
REM – The below command checks for the temporary internet files directory.
:ifthen
if exist “%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5” call :ContentDelete1 %1
if exist “%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5” call :ContentDelete2 %1
if exist “%HDRIVE%\%HPATH%\%1\Local Settings\temp” call :TempDelete %1
goto :EOF
REM – The below code removes all folders located at ‘Profile\Local Settings\Temporary Internet Files\Content.IE5’
REM – It then returns back to the line that it was called from.
:ContentDelete1
cd “%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5”
if exist “%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5” for /d %%n in (*) do rd /s /q “%%n”
if exist “%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5” del /q “%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5\*”
goto :EOF
REM – The below code removes all folders located at ‘windows\Temporary Internet Files\Content.IE5’
:ContentDelete2
cd “%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5”
if exist “%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5” for /d %%n in (*) do rd /s /q “%%n”
if exist “%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5” del /q “%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5\*”
goto :EOF
REM – The below code removes all folders located at ‘windows\Temporary Internet Files\Content.IE5’
:TempDelete
cd “%HDRIVE%\%HPATH%\%1\Local Settings\Temp”
if exist “%HDRIVE%\%HPATH%\%1\Local Settings\Temp” for /d %%n in (*) do rd /s /q “%%n”
if exist “%HDRIVE%\%HPATH%\%1\Local Settings\Temp” del /q “%HDRIVE%\%HPATH%\%1\Local Settings\Temp\*”
goto :EOF
:end