2017-09-27 80 views
0
一個問題

我的問題是PowerShell中總是給我的錯誤信息:「着覆蓋文件與自己」,我不知道爲什麼我有拷貝項目在PowerShell中

$source=$textBox1.text 
$dest=$textBox2.Text 
$usr=$textBox3.text 
##### ##從
$fNoBackup =    "\\$source\c$\Users\$usr\AppData\Local\NoBackup\*" 
$fData =     "\\$source\c$\Users\$usr\AppData\Local\Lotus\Notes\Data\*" 
$fCustomDestinations =  "\\$source\c$\Users\$usr\AppData\Roaming\Microsoft\Windows\Recent\CustomDestinations\*" 
$fAutomaticDestinations = "\\$source\c$\Users\$usr\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\*" 
#######要
$tNoBackup =    "\\$dest\c$\Users\$usr\AppData\Local\NoBackup" 
$tData =     "\\$dest\c$\Users\$usr\AppData\Local\Lotus\Notes\Data" 
$tCustomDestinations =  "\\$dest\c$\Users\$usr\AppData\Roaming\Microsoft\Windows\Recent\CustomDestinations" 
$tAutomaticDestinations = "\\$dest\c$\Users\$usr\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations" 
#######樂複製
#############"Touch" the files ;D 
New-Item -ItemType File -Path $tNoBackup -Force 
New-Item -ItemType File -Path $tData -Force 
New-Item -ItemType File -Path $tCustomDestinations -Force 
New-Item -ItemType File -Path $tAutomaticDestinations -Force 

#############Copy 
Copy-Item $fNoBackup    $tNoBackup -Recurse -Force 
Copy-Item $fData     $tData -Recurse -Force 
Copy-Item $fCustomDestinations  $tCustomDestinations -Recurse -Force 
Copy-Item $fAutomaticDestinations $tAutomaticDestinations -Recurse -Force 
+0

我的回答對你有幫助嗎? – Binarus

回答

0

要調試這一點,我會建議日在你打印出你的變量的內容到控制檯。這樣,你就會明白問題所在。

我不知道Powershell,但我看到的東西可能是一個問題。顯然,$內的一個字符串具有特殊的含義(它似乎表示變量)。因此,我懷疑如果您希望它是字符串中的字面量,您必須引用(轉義)$符號。

在每個字符串中,您都有c$。那應該是c`$,因爲`是Powershell中的轉義字符。完成此操作後,再次將字符串輸出到控制檯,以確保您獲得正確的字符串。