在下面附加的專案目錄結構中,我試圖僅將一月的子目錄(即Product1_2022-01
和)復制到存檔中的檔案夾中Product2_2022-01
,包括其中包含的檔案。然而,雖然子目錄(和內容)是根據需要復制的,但上一級目錄和目錄2022-01
中的二月檔案,即檔案和,也被復制。Product1
Product2
fileA-02
fileB-02
是否可以只復制子目錄及其內容?我已經包含了重現上述場景的代碼。我是 PowerShell 的新手,所以任何幫助或建議將不勝感激,謝謝。
目錄結構
代碼:
$source = @("C:\Product\Testing\Tested\Product1\*",
"C:\Product\Testing\Tested\Product2\*"
)
$destination = "C:\Archive\2022\2022-01"
Copy-Item -Path $source -Destination $destination -Recurse
uj5u.com熱心網友回復:
您明確告訴它復制Product1\*
, 和Product2\*
. 如果您希望將其縮小到僅子檔案夾,請指定整個路徑 ( Product1\Product1_2022_01
),或僅指定路徑的一部分 ( Product1\Product*
):
$source = @("C:\Product\Testing\Tested\Product1\Product*",
"C:\Product\Testing\Tested\Product2\Product*"
)
$destination = "C:\Archive\2022\2022-01"
Copy-Item -Path $source -Destination $destination -Recurse
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507987.html