2015-02-10 51 views
0
$from = ".\test\Application Data\software1\config\1.0" 
$to = ".\test\Profile2k8\Appdata" 

$exclude = @("new.ini","new2.ini") 

Get-ChildItem $from -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $to $_.FullName.Substring($from.length)} 

當我運行此腳本,它將複製文件,但它也包括在目標路徑中像這樣的數據文件夾:爲什麼這個文件夾是PowerShell的複製遞歸創建一個數據文件夾

.\test\Profile2k8\Appdata\n Data\software1\config\1.0 

創建,我怎樣才能防止這一點?

感謝這麼多提前

回答

0

會改變$_.FullName.Substring($from.length) 只是$_.Name工作如預期的吧?

編輯:哦,對,現在注意到遞歸位,這可能會改變事情。

0

在最後更改的代碼行下面,我希望它會與合作:

Get-ChildItem $from -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $to $_.FullName.Substring((Convert-Path $from).length)} 

你的代碼試圖獲取字符串$from的長度(只包含一個相對路徑和不完整路徑),但實際的路徑長度爲更多的東西,因爲它可能是像

"C:\test\Application Data\software1\config\1.0" 
+0

現在,它只是複製的 內容\測試\應用數據中\軟件1 \ CONFIG \ 1.0 直接: 。\ test \ Profile2k8 \ Appdata 沒有創建軟件\ config \ 1.0文件夾 – Klausmaus 2015-02-10 08:17:27

+0

你的意思是說遞歸heirarchy不會出現在目標文件夾中嗎? – RinoTom 2015-02-10 08:26:08

+0

yes/no來自「。\ test \ Application Data \ software1 \ config \ 1.0」 下面的所有文件夾正在創建,但\ software1 \ config \ 1.0部分不是 – Klausmaus 2015-02-10 08:34:40

相關問題