小编use*_*721的帖子

Test-Path无法在存在的文件上返回$ True

我试图验证文件的存在,但问题是文件名在名称中有括号,即c:\ test [R] 10005404,失败的注释,[S] SiteName.txt.

我尝试使用字符串.replace方法但没有成功.

$a = c:\test\[R] 10005404, Failed with Comments, [S] SiteName.txt
$Result = (Test-Path $a)
# Returns $False even though the file exists.
Run Code Online (Sandbox Code Playgroud)

试着

$a = $a.Replace("[", "`[")
$a = $a.Replace("]", "`]")

$Result = (Test-Path $a)
# Also returns $False even though the file exists.
Run Code Online (Sandbox Code Playgroud)

想法将不胜感激.谢谢,ChrisM

powershell powershell-ise powershell-2.0

9
推荐指数
2
解决办法
1万
查看次数