Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 41 additions & 29 deletions cleaner.bat
Original file line number Diff line number Diff line change
@@ -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