@echo off
:: ============================================================
:: CleanTempFiles.bat
::
:: Clears the current user's %TEMP% folder and the Windows
:: Temp folder, plus the Recycle Bin, to free up disk space.
:: Files currently in use are silently skipped.
::
:: Usage:
::   CleanTempFiles.bat            (asks for confirmation)
::   CleanTempFiles.bat /silent    (no prompt, no pause at end)
:: ============================================================

setlocal EnableDelayedExpansion

set "SILENT=0"
if /I "%~1"=="/silent" set "SILENT=1"

if "%SILENT%"=="0" (
    echo This will delete temporary files from:
    echo   - %TEMP%
    echo   - C:\Windows\Temp
    echo   - Recycle Bin
    echo.
    set /p CONFIRM="Continue? (Y/N): "
    if /I not "!CONFIRM!"=="Y" (
        echo Cancelled.
        goto :EOF
    )
)

echo.
echo Cleaning user temp folder: %TEMP%
del /f /s /q "%TEMP%\*.*" >nul 2>&1
for /d %%D in ("%TEMP%\*") do rd /s /q "%%D" >nul 2>&1

echo Cleaning Windows temp folder: C:\Windows\Temp
del /f /s /q "C:\Windows\Temp\*.*" >nul 2>&1
for /d %%D in ("C:\Windows\Temp\*") do rd /s /q "%%D" >nul 2>&1

echo Emptying Recycle Bin
powershell -NoProfile -Command "Clear-RecycleBin -Force -ErrorAction SilentlyContinue"

echo.
echo Done. Some files may have been skipped if they were in use.

if "%SILENT%"=="0" pause
endlocal
