Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows 8 一鍵清除垃圾檔案:自製 BAT 批次檔腳本教學

編輯:Win8 系統應用技巧

Windows 8 內建磁碟清理功能固然好用,但若想更徹底、自動化清除暫存檔、日誌、快取等垃圾檔案,自製批次檔(.bat)是輕量級的好選擇。本文提供現成腳本碼與製作步驟,雙擊即執行,無需安裝第三方軟體。

製作步驟

  1. 桌面右鍵 → 新增 →「文字文件」。
  2. 貼上下方完整腳本碼。
  3. 另存新檔,檔名改為 CleanJunk.bat(副檔名必須為 .bat)。
  4. 以系統管理員身分執行(右鍵 →「以系統管理員身分執行」),靜待完成。

新增文字文件

貼上腳本碼

更改副檔名為bat

執行畫面

批次檔腳本內容(複製即用)

@echo off
color 1e
echo 正在清理系統垃圾檔案,請稍候...
for /r c: %%a in (*.tmp *.chk *.gid *._mp *.old *.bak *.log) do del /f /s /q "%%a"
for /r c:\windows\temp %%a in (*.*) do del /f /s /q "%%a"
for /r c:\windows\Prefetch %%a in (*.*) do del /f /s /q "%%a"
for /r "%userprofile%\AppData\Local\Temp" %%a in (*.*) do del /f /s /q "%%a"
for /r "%localappdata%\Microsoft\Windows\Temporary Internet Files" %%a in (*.*) do del /f /s /q "%%a"
for /r "%localappdata%\Microsoft\Windows\History" %%a in (*.*) do del /f /s /q "%%a"
for /r "%appdata%\Microsoft\Windows\Cookies" %%a in (*.*) do del /f /s /q "%%a"
for /r "%windir%\SoftwareDistribution\Download" %%a in (*) do del /f /s /q "%%a"
for /r "%windir%\Downloaded Program Files" %%a in (*) do del /f /s /q "%%a"
for /r "%windir%\System32\LogFiles" %%a in (*) do del /f /s /q "%%a"
del /f /s /q %systemdrive%\hiberfil.sys
echo 清理完成!
pause

腳本清理範圍說明

  • 各磁碟根目錄下的暫存副檔名檔案
  • Windows\Temp、Prefetch、軟體發佈下載快取
  • 使用者暫存資料夾、IE 快取/歷史/ Cookie
  • 下載的程式檔案、系統日誌、休眠檔

⚠ 重要提醒

  • 必須以系統管理員權限執行,否則受保護資料夾無法刪除。
  • 執行過程會彈出 CMD 視窗顯示進度,請勿關閉。
  • 腳本使用 del /f /s /q 強制刪除,無法復原,請確認無重要檔案誤判為垃圾檔。
  • 建議每月執行一次,或於安裝大型軟體/更新後執行。
Copyright © Windows教程網 All Rights Reserved