From 7b4492b9b0e150d53e342eaecc06dd18d1aed837 Mon Sep 17 00:00:00 2001 From: goravine <82170185+goravine@users.noreply.github.com> Date: Mon, 16 Mar 2026 09:08:07 +0700 Subject: [PATCH] Update cleaner.bat for improved clarity and functionality --- cleaner.bat | 70 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/cleaner.bat b/cleaner.bat index 49fd971..ffea8b9 100644 --- a/cleaner.bat +++ b/cleaner.bat @@ -1,67 +1,79 @@ @echo off cls -title Miguel's File Cleaner (Updated for Windows 11) +title Miguel's File Cleaner (Windows 11 Safe) :: Check for administrative privileges net session >nul 2>&1 if %errorLevel% neq 0 ( - echo Please run this script as an administrator. + echo Please run this script as Administrator. pause exit ) :: Define log file -set LogFile=%~dp0FileCleaner.log +set "LogFile=%~dp0FileCleaner.log" + +echo =============================== >> "%LogFile%" +echo Run Date: %date% %time% >> "%LogFile%" +echo =============================== >> "%LogFile%" :: User confirmation -echo This script will clean temporary files and free up disk space. +echo This script will clean temporary files and free disk space. set /p UserInput=Do you want to proceed? (Y/N): if /i not "%UserInput%"=="Y" exit echo Cleaning temporary files... +echo. -:: Function to delete files and directories -:CleanDir -if exist "%~1" ( - echo Cleaning %~1... >> "%LogFile%" - del /s /f /q "%~1\*.*" >> "%LogFile%" 2>&1 - for /d %%i in ("%~1\*") do rd /s /q "%%i" >> "%LogFile%" 2>&1 -) else ( - echo Directory %~1 does not exist. Skipping... >> "%LogFile%" -) -goto :eof - -:: Clean Windows Temp folder +:: Clean Windows Temp call :CleanDir "C:\Windows\Temp" -:: Clean user Temp folder +:: Clean User Temp call :CleanDir "%TEMP%" -:: Clean Prefetch folder -call :CleanDir "C:\Windows\Prefetch" - -:: Clean Internet Explorer temporary files (if applicable) +:: Clean Internet Cache call :CleanDir "%LOCALAPPDATA%\Microsoft\Windows\INetCache" -:: Clean Edge temporary files +:: Clean Edge Cache call :CleanDir "%LOCALAPPDATA%\Microsoft\Edge\User Data\Default\Cache" -:: Clean recent files +:: Clean Recent Files call :CleanDir "%APPDATA%\Microsoft\Windows\Recent" -:: Clean Windows Update cache +:: Clean Windows Minidump +call :CleanDir "C:\Windows\Minidump" + +:: Clean Windows Update Cache (requires stopping service) +echo Stopping Windows Update Service... +net stop wuauserv >nul 2>&1 + call :CleanDir "C:\Windows\SoftwareDistribution\Download" -:: Clean system error memory dump files -call :CleanDir "C:\Windows\Minidump" +echo Starting Windows Update Service... +net start wuauserv >nul 2>&1 :: Empty Recycle Bin echo Emptying Recycle Bin... -PowerShell.exe -NoProfile -Command "Clear-RecycleBin -Confirm:$false" >> "%LogFile%" 2>&1 +PowerShell -NoProfile -Command "Clear-RecycleBin -Force" >> "%LogFile%" 2>&1 echo. -echo All specified temporary files have been cleaned. -echo Log file created at %LogFile% +echo Cleaning completed. +echo Log file saved to: +echo %LogFile% echo. + pause exit + + +:CleanDir +if exist "%~1" ( + echo Cleaning %~1 ... + echo Cleaning %~1 >> "%LogFile%" + + del /s /f /q "%~1\*.*" >> "%LogFile%" 2>&1 + for /d %%i in ("%~1\*") do rd /s /q "%%i" >> "%LogFile%" 2>&1 +) else ( + echo Skipping %~1 (not found) >> "%LogFile%" +) +exit /b