萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Windows XP 教學

Windows 系統垃圾清理批次檔:一鍵清除 Temp、Prefetch、Cookies、IE 快取等

長期使用 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

使用說明

  1. 將上述內容存為 CleanJunk.bat(編碼 UTF-8 with BOM 或 ANSI)。
  2. 以**系統管理員身分執行**(右鍵 → 以系統管理員身分執行),確保有權限清理系統目錄。
  3. 可建立捷徑放入「啟動」資料夾或排程工作每週自動執行。

變數說明

  • %SystemDrive%:系統磁碟代號(通常 C:)。
  • %WinDir%:Windows 目錄(通常 C:\Windows)。
  • %UserProfile%:目前使用者設定檔路徑。
  • %LocalAppData% (Vista+):%UserProfile%\AppData\Local。

補充:PowerShell 版本(更強大、支援進度列、錯誤處理)

$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 清除會導致網站登出,重要站台建議手動保留或使用瀏覽器內建清理(可保留特定網域)。
  • 若使用 SSD,頻繁大量刪寫對壽命影響極微,但建議啟用 TRIM(Win7+ 預設開啟)。
  • 此批次檔**不清理**瀏覽器內建資料庫、密碼、書籤、擴充套件快取,請配合瀏覽器設定清理。
copyright © 萬盛學電腦網 all rights reserved