簡體   English   中英

我在Powershell中遇到復制項問題

[英]I have a Issue with Copy-Item in Powershell

我的問題是Powershell總是給我錯誤消息msg:“自己無法覆蓋文件”,我不知道為什么

$source=$textBox1.text
$dest=$textBox2.Text
$usr=$textBox3.text
#######從
#############"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
#######至
 $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" 
####### le復制
 #############"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 

要進行調試,建議您將變量的內容輸出到控制台。 這樣,您將了解問題所在。

我不了解Powershell,但是我看到的東西可能是個問題。 顯然,字符串中的$具有特殊含義(它似乎表示變量)。 因此,我懷疑如果要在字符串中使用原義字符,則必須引用(轉義) $符號。

在每個字符串中,都有c$ 可能應該是c`$因為`是Powershell中的轉義字符。 完成此操作后,再次將字符串打印到控制台,以確保正確無誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM