windows powershell检查文件存在不起作用

时间:2014-11-02 09:58:26

标签: powershell

我正在学习PowerShell,我发现它的行为很奇怪。基本上,我无法获得任何示例脚本(来自互联网)。

例如,这一个:

$WantFile = "C:\Users\psuser\Documents\GitHub\test\Bin\test.exe" 
$FileExists = Test-Path $WantFile 
If ($FileExists -eq $True) {Write-Host "Yippee"}
Else {Write-Host "No file at this location"}

看起来很简单,从bash的角度来看,但我被告知:

C:\Users\psuser\Documents\GitHub\test>$FileExists = Test-Path $WantFile
'$FileExists' is not recognized as an internal or external command,
operable program or batch file.
-eq was unexpected at this time.

任何人都可以快速告诉我哪里弄错了吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您必须在Powershell中运行此命令。

来自CMD

powershell -command "&{Test-Path 'C:\Users\psuser\Documents\GitHub\test\Bin\test.exe'}"