2014-09-02 134 views
0

我有一個非常簡單的問題,但我沒有得到它的工作。我有一個循環,檢查兩個可能的文件之一是否存在,如果沒有,然後在兩秒鐘內再次檢查。PowerShell:或While循環中的條件

while (([System.IO.File]::Exists($terminationFile) -ne $true) -or ([System.IO.File]::Exists($noFile) -ne $true)) { 
    # wait 2 seconds and check again 
    Start-Sleep -s 2 
} 

如果我在同一個循環中檢查兩個條件,它只檢查第一個條件。

將是巨大的,如果有人能幫助

問候, 賈斯汀

+2

你大概的意思是:雖然((測試的路徑$ terminationFile )和!(Test-Path $ noFile)){Start-Sleep -s 2} – 2014-09-02 14:32:46

+0

謝謝,我會試試看。但是,當我只檢查:while([System.IO.File] :: Exists($ terminationFile)-ne $ true)時爲什麼它工作? – nitsuj1001 2014-09-02 14:40:37

+0

太棒了,現在似乎在工作。謝謝! – nitsuj1001 2014-09-02 14:55:35

回答

0

David Brant進行闡釋工作對我來說:

while (!(Test-Path -Path $terminationFile) -or !(Test-Path -Path $noFile)) { 
    Start-Sleep 2 
}