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

Windows 下批量刪除 .svn 隱藏資料夾的最簡批處理腳本

編輯:系統常見問題解答

專案遷移或匯出時常需剔除 Subversion 版本控制資料夾(.svn)。以下提供一支功能完整的批處理檔(clean_svn.bat),支援遞迴刪除、互動確認、路徑還原。

腳本完整碼

@echo off
echo ***********************************************************
echo 清除 SVN 版本資訊
echo ***********************************************************
:start
set pwd=%cd%
cd /d %1
echo 目前工作目錄:& chdir
:input
set choice=
set /p choice=確定要清除目前目錄下的 .svn 資訊嗎?[Y/N/Q]
if "%choice%"=="y" goto clean
if "%choice%"=="Y" goto clean
if "%choice%"=="n" goto noclean
if "%choice%"=="N" goto noclean
if "%choice%"=="q" goto end
if "%choice%"=="Q" goto end
goto input
:clean
@echo on
for /d /r %%c in (.svn) do @if exist "%%c" ( rd /s /q "%%c" & echo 刪除目錄 %%c )
@echo off
echo "目前目錄下的 SVN 資訊已清除"
goto end
:noclean
echo "SVN 清除操作已取消"
goto end
:end
cd /d "%pwd%"
pause

使用方式

  1. 將上述碼存為 clean_svn.bat。
  2. 命令列執行:clean_svn.bat 目標專案路徑(不帶參數則清理當前目錄)。
  3. 依提示輸入 Y 確認刪除,N 取消,Q 退出。

原理解析

  • for /d /r %%c in (.svn) 遞迴尋找所有名為 .svn 的目錄。
  • rd /s /q 安靜模式強制刪除目錄及其內容。
  • 腳本記錄原始路徑(pwd),結束時自動返回,不影響後續操作。

提示:若專案極大,刪除過程可能持續數秒至數分鐘,請耐心等待。

Copyright © Windows教程網 All Rights Reserved