如何將資料夾從一個目錄複製到另一個目錄並覆蓋資料夾而不是合併資料夾?

如何將資料夾從一個目錄複製到另一個目錄並覆蓋資料夾而不是合併資料夾?

我有兩個資料夾

- source
 folderA
 folderB
 folderC
 folderD

- destination
 folderA
 folderB
 folderE
 folderF

我想使用 powershell 將來源的所有直接子級複製到目標並替換資料夾而不是合併它們。即:在範例中,folderAondestination將被folderAin取代source(相當於刪除destination/folderA,然後複製source/folderA

答案1

如上所述,Robocopy 非常適合這些類型的流程。

這是一個利用 Powershell 中 Robocopy 的「鏡像」選項的簡單腳本:

  # Change the Source Folder Below
$Src = "X:\Source\Folder"
  # Change the Destination Folder Below
$Dest = "Y:\Destination\Folder"
  # The MIR Option
$Opt = "/mir"
Robocopy "$Src" "$Dest" "$Opt"

Robocopy 實用程式非常強大且快速,並提供更多參數和選項。它們可以在這裡找到: 微軟的 Robocopy 頁面

相關內容