@echo off
:: ============================================================
:: CleanTempFiles.bat
::
:: Clears the current user's Temp folder. Asks for confirmation first.
::
:: Usage:
::   CleanTempFiles.bat            (asks for confirmation)
::   CleanTempFiles.bat /silent    (no prompt, no pause at end)
:: ============================================================

setlocal EnableDelayedExpansion
set "TARGET=%TEMP%"
set "SILENT=0"
if /I "%~1"=="/silent" set "SILENT=1"

if not exist "%TARGET%" (
    echo %TARGET% does not exist on this machine.
    goto :EOF
)

if "%SILENT%"=="0" (
    echo This will delete the contents of:
    echo   %TARGET%
    echo.
    set /p CONFIRM="Continue? (Y/N): "
    if /I not "!CONFIRM!"=="Y" (
        echo Cancelled.
        goto :EOF
    )
)

del /f /s /q "%TARGET%\*.*" >nul 2>&1
for /d %%D in ("%TARGET%\*") do rd /s /q "%%D" >nul 2>&1

echo Cleanup complete. Some files may have been skipped if they were in use.
if "%SILENT%"=="0" pause
endlocal