Clean up Temp Files – Windows Batch File
BAT (Batchfile)
@echo off
echo Cleaning up temporary files...
:: Prompt user for confirmation
set /p confirm=Are you sure you want to delete temporary files? (Y/N):
if /i not %confirm%==Y goto end
:: Delete files from various temp directories
echo Deleting files from %SystemRoot%\Temp...
del /f /s /q "%SystemRoot%\Temp\*.*"
rd /s /q "%SystemRoot%\Temp"
echo Deleting files from %SystemRoot%\System32\config\systemprofile\AppData\Local\Temp...
del /f /s /q "%SystemRoot%\System32\config\systemprofile\AppData\Local\Temp\*.*"
rd /s /q "%SystemRoot%\System32\config\systemprofile\AppData\Local\Temp"
echo Deleting files from %LOCALAPPDATA%\Temp...
del /f /s /q "%LOCALAPPDATA%\Temp\*.*"
rd /s /q "%LOCALAPPDATA%\Temp"
echo Deleting files from %USERPROFILE%\AppData\Local\Temp...
del /f /s /q "%USERPROFILE%\AppData\Local\Temp\*.*"
rd /s /q "%USERPROFILE%\AppData\Local\Temp"
:: Clean up Windows Update cache (optional, uncomment if needed)
:: echo Deleting Windows Update cache...
:: del /f /s /q "%SystemRoot%\SoftwareDistribution\Download\*.*"
:: rd /s /q "%SystemRoot%\SoftwareDistribution\Download"
:: Clean up Windows prefetch files (optional, uncomment if needed)
:: echo Deleting Windows prefetch files...
:: del /f /s /q "%SystemRoot%\Prefetch\*.*"
:: rd /s /q "%SystemRoot%\Prefetch"
echo Temporary files cleanup completed.
:end
pause
exit