長期使用 Windows 會累積大量暫存檔、日誌、預讀快取、瀏覽器快取,佔用磁碟空間並拖慢搜尋/開機速度。一支批次檔即可自動化清理常見垃圾路徑,支援變數路徑、多使用者環境。
CleanJunk.bat@echo off
chcp 65001 >nul
echo 正在清理系統垃圾檔案,請稍候......
echo.
:: 系統層級暫存
del /f /s /q "%SystemDrive%\*.tmp" 2>nul
del /f /s /q "%SystemDrive%\*._mp" 2>nul
del /f /s /q "%SystemDrive%\*.log" 2>nul
del /f /s /q "%SystemDrive%\*.gid" 2>nul
del /f /s /q "%SystemDrive%\*.chk" 2>nul
del /f /s /q "%SystemDrive%\*.old" 2>nul
del /f /s /q "%SystemDrive%\Recycled\*.*" 2>nul
del /f /s /q "%SystemDrive%\Recycler\*.*" 2>nul
del /f /s /q "%SystemDrive%\$Recycle.Bin\*.*" 2>nul
:: Windows 目錄
del /f /s /q "%WinDir%\*.bak" 2>nul
del /f /s /q "%WinDir%\Prefetch\*.*" 2>nul
rd /s /q "%WinDir%\Temp" 2>nul
md "%WinDir%\Temp" 2>nul
:: 當前使用者
del /f /q "%UserProfile%\Cookies\*.*" 2>nul
del /f /q "%UserProfile%\Recent\*.*" 2>nul
del /f /s /q "%UserProfile%\Local Settings\Temporary Internet Files\*.*" 2>nul
del /f /s /q "%UserProfile%\Local Settings\Temp\*.*" 2>nul
del /f /s /q "%UserProfile%\AppData\Local\Temp\*.*" 2>nul
del /f /s /q "%UserProfile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" 2>nul
del /f /s /q "%UserProfile%\AppData\Local\Microsoft\Windows\INetCache\*.*" 2>nul
del /f /s /q "%UserProfile%\AppData\Local\Microsoft\Windows\History\*.*" 2>nul
echo.
echo 清理完成!
pause
CleanJunk.bat(編碼 UTF-8 with BOM 或 ANSI)。%SystemDrive%:系統磁碟代號(通常 C:)。%WinDir%:Windows 目錄(通常 C:\Windows)。%UserProfile%:目前使用者設定檔路徑。%LocalAppData% (Vista+):%UserProfile%\AppData\Local。$paths = @(
"$env:SystemDrive\*.tmp",
"$env:SystemDrive\*.log",
"$env:WinDir\Prefetch\*",
"$env:WinDir\Temp\*",
"$env:LocalAppData\Temp\*",
"$env:LocalAppData\Microsoft\Windows\INetCache\*",
"$env:LocalAppData\Microsoft\Windows\History\*",
"$env:UserProfile\Cookies\*",
"$env:UserProfile\Recent\*"
)
foreach ($p in $paths) {
Write-Host "清理 $p ..."
Get-ChildItem -Path $p -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
}
Write-Host "清理完成。" -ForegroundColor Green
Read-Host "按 Enter 結束"
Prefetch 後首次開機/啟動程式會稍慢(重建佈局),屬正常現象。Cookies 清除會導致網站登出,重要站台建議手動保留或使用瀏覽器內建清理(可保留特定網域)。