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

CMD 指令高效複製/刪除資料夾:xcopy 與 rd 完整參數教學

編輯:Windows 7 系統介紹

複製資料夾:xcopy

xcopy F:\File C:\File /E /H /K /Y
  • /E:含子目錄(空目錄也複製)。
  • /H:含隱藏/系統檔。
  • /K:保留唯讀屬性。
  • /Y:不提示覆蓋確認。
  • /I:目的若不存在假設為目錄(批次檔建議加上)。

刪除資料夾:rd (rmdir)

del 只能刪檔案,不能刪資料夾**。

:: 刪除 D:\123 及所有內容,不提示
rd /S /Q D:\123
  • /S:遞迴刪除子目錄與檔案。
  • /Q:安靜模式(需搭配 /S)。

常見錯誤

  • del /S /Q D:\123\*.* → 僅刪檔案,資料夾殘留。
  • rd D:\123 → 非空目錄報錯,必須加 /S。

進階用法

  • 超長路徑:rd /S /Q "\\?\D:\Very\Long\Path"
  • 批次刪除多個符合模式資料夾:
    for /d %i in (D:\Temp_*) do rd /S /Q "%i"
  • 搭配 xcopy /L 預覽將複製項目再實際執行。
CMD 複製刪除示意
Copyright © Windows教程網 All Rights Reserved