nitsuj1001
nitsuj1001

Reputation: 51

PowerShell: Or Condition in While Loop

I've a really simple problem, but i dont get it working. I have a loop which checks if one of two possible files is existing, if not then sleep and check again in two seconds.

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
}

If I check both conditions in the same loop it checks only the first one.

Would be great if anybody can help

Regards, Justin

Upvotes: 0

Views: 23724

Answers (1)

merkucio L
merkucio L

Reputation: 31

An interpretaion of David Brant worked for me:

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

Upvotes: 3

Related Questions