所以我试图检查路径是否可用。我用测试路径做这个
它看起来像这样:
$c="C:\"
$d="D:\"
$e="E:\"
if(Test-Path $c -eq "False"){
}
elseif(Test-Path $d -eq "False"){
}
elseif(Test-Path $e -eq "False"){
}
else{
"The File doesn't exist"
}
Run Code Online (Sandbox Code Playgroud)
那么如果错误看起来像这样,我做错了什么:
Test-Path : A parameter cannot be found that matches parameter name 'eq'.
At C:\Users\boriv\Desktop\ps\Unbenannt1.ps1:23 char:17
+ If(Test-Path $c -eq "False"){
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Test-Path], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.TestPathCommand`
Run Code Online (Sandbox Code Playgroud)
您不想比较Test-Pathcmdlet的结果,因此您需要使用括号,否则-eq参数将传递给Test-Pathcmdlet,这就是您收到错误的原因。
我会使用-not运算符,因为我发现它更具可读性。例子:
if(-not (Test-Path $c)) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9104 次 |
| 最近记录: |