@echo off setlocal EnableExtensions net session >nul 2>&1 if errorlevel 1 ( echo Administrator rights are required. exit /b 1 ) set "TARGET=%SystemRoot%\Temp" if not exist "%TARGET%\" ( echo Folder not found: %TARGET% exit /b 1 ) echo WARNING: Windows Temp may contain files used by running installers. echo Files older than 7 days in %TARGET%: forfiles /p "%TARGET%" /m * /d -7 /c "cmd /c if @isdir==FALSE echo @path" 2>nul echo. set "ANSWER=" set /p ANSWER=Delete these files? Type YES to continue: if /i not "%ANSWER%"=="YES" ( echo Cancelled. Nothing deleted. exit /b 0 ) forfiles /p "%TARGET%" /m * /d -7 /c "cmd /c if @isdir==FALSE del /f /q @path" 2>nul echo Done. Some in-use files may remain. exit /b 0