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

Win7一鍵清理系統垃圾?自製BAT批次檔免安裝第三方工具

編輯:Windows 7 系統介紹

Windows 7 使用久了會產生大量暫存檔、日誌、快取、回收站殘留,佔用磁碟空間並拖慢系統。無需安裝「清理大師」「C 盤瘦身」等第三方工具,自製一個 .bat 批次檔,雙擊即可一鍵清理核心垃圾目錄,安全、透明、可自訂。

製作步驟

  1. 桌面新建文字文件,命名 CleanJunk.txt。
  2. 貼入以下指令碼:
@echo off
echo 正在清除系統垃圾檔案,請稍候......
del /f /s /q %%systemdrive%%\*.tmp
del /f /s /q %%systemdrive%%\*._mp
del /f /s /q %%systemdrive%%\*.log
del /f /s /q %%systemdrive%%\*.gid
del /f /s /q %%systemdrive%%\*.chk
del /f /s /q %%systemdrive%%\*.old
del /f /s /q %%systemdrive%%\recycled\*.*
del /f /s /q %%windir%%\*.bak
del /f /s /q %%windir%%\prefetch\*.*
rd /s /q %%windir%%\temp & md %%windir%%\temp
del /f /q %%userprofile%%\cookies\*.*
del /f /q %%userprofile%%\recent\*.*
del /f /s /q "%%userprofile%%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%%userprofile%%\Local Settings\Temp\*.*"
del /f /s /q "%%userprofile%%\recent\*.*"
echo 清除系統垃圾完成!
pause
  1. 另存為 CleanJunk.bat(編碼 ANSI,副檔名 .bat)。
  2. 確認變更副檔名提示選「是」。
  3. 滑鼠右鍵 CleanJunk.bat →「以系統管理員身分執行」(清理系統目錄需權限)。
  4. 等待視窗顯示「清除系統垃圾完成!」按任意鍵關閉。

指令碼解析與自訂建議

  • %%systemdrive%% = 系統盤(通常 C:),%%windir%% = Windows 目錄,%%userprofile%% = 使用者設定檔目錄。
  • Prefetch 清理爭議: 刪除 prefetch\*.* 會導致下次啟動程式稍慢(重新建立預讀),建議保留或改為手動清理。
  • 擴充清理目錄: 可加入 %%windir%%\SoftwareDistribution\Download\*.*(Windows Update 快取)、%%userprofile%%\AppData\Local\Temp\*.*。
  • 安全優先: 指令碼僅刪除已知安全的暫存/快取/日誌副檔名,不刪除使用者文件、下載資料夾、桌面檔案。

內建替代方案

  • 磁碟清理: 右鍵 C: →「內容」→「磁碟清理」→「清理系統檔案」,勾選所有項目確定,官方原生、最安全。
  • 儲存體感知: Win10/11 內建,Win7 無此功能。

自製 BAT 批次檔,乾淨無廣告、無捆綁、可攜帶、可版控,是極客/管理員首選清理方式。

Copyright © Windows教程網 All Rights Reserved