Powershell测试路径不起作用?

时间:2016-10-04 17:28:06

标签: powershell testing path

哇。我今天必须服用愚蠢的药片。我在脚本中使用了一个简单的测试路径,当文件 存在时,我无法弄清楚它为什么不进入IF块。我在ISE命令窗口中运行相同的代码,它工作正常:

$allfile="c:\users\rs02130\desktop\sonarRules\jsrulesall.xlsx"
Write-Output "Testing $allfile"
if (Test-Path $allfile) 
{
    Write-Output "In If"
    try
    {
        Write-Output "Removing $allfile"
        Remove-Item $allfile -Force -ErrorAction Stop
        Write-Output "Removed $allfile"
    }
    catch
    {
        Write-Error "Error removing $allfile"
        exit 1
    }
}
显然,我错过了一些基本的东西,但我没有得到它。完整的原始脚本在另一个区域有类似的代码,它工作正常。

1 个答案:

答案 0 :(得分:0)

想出来。一个坏文件通配符的组合进一步向上,在我进一步向下之前删除文件和Get-ChildItem与Write-Host的异步性质导致我认为文件是在那里时它不是。