我有一个脚本尝试使用相对路径运行一些可执行文件。
因此,我使用test-path
来验证可执行文件是否在预期的位置。
如果没有,我尝试其他位置。
if(test-path "$current../../../myexe.exe"){
# found it!
}
但是在这种情况下,如果$ current是
C:/folder/
,则test-path "C:/folder/../../../myexe.exe"
失败,并显示The path ... referred to an item that was outside the base 'C:'
有没有一种干净可靠的方法来测试路径,以便它返回true或false,并且不会抛出一些意外错误?
最佳答案
关于powershell - 如何在Powershell中测试无效路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15900121/