[英]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.