blu*_*are 6 powershell environment-variables
情况是这样的:
PS C:\Users\user> copy %USERPROFILE%\AppData\Local\Thing %USERPROFILE%\AppData\Local\Thing.backup
copy : Cannot find path 'C:\Users\user\%USERPROFILE%\AppData\Local\Thing' because it does not
exist.
At line:1 char:1
+ copy %USERPROFILE%\AppData\Local\Thing %USERPROFILE%\AppData\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\user...\Thing:String) [Copy-Item], ItemN
otFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
Run Code Online (Sandbox Code Playgroud)
它在文字 %USERPROFILE% 前面插入扩展的 %USERPROFILE%。
它在做什么?我怎样才能防止这种情况发生?
Was*_*sif 11
在 powershell 中你需要使用$env:UserProfile:
copy "$($env:USERPROFILE)\AppData\Local\Thing" "$($env:USERPROFILE)\AppData\Local\Thing.backup"
Run Code Online (Sandbox Code Playgroud)
$()。copy是 powershell Cmdlet 的别名Copy-Item。旁注:如果您需要使用文字,'%USERPOFILE%'请使用-LiteralPath或使用单引号。
| 归档时间: |
|
| 查看次数: |
15233 次 |
| 最近记录: |