0

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

3
  • 2
    You probably mean: while (!(Test-Path $terminationFile) -and !(Test-Path $noFile)) { Start-Sleep -s 2 } Commented Sep 2, 2014 at 14:32
  • Thank you, I'll try it. But why is it working when I only check for: while ([System.IO.File]::Exists($terminationFile) -ne $true) ? Commented Sep 2, 2014 at 14:40
  • It because if the first check succeeds IE its false then the second check is never run. If the first check fails then it would check the second. If you want both checks to succeed before doing anything use -and like David said Commented Sep 2, 2014 at 15:11

1 Answer 1

3

An interpretaion of David Brant worked for me:

while (!(Test-Path -Path $terminationFile) -or !(Test-Path -Path $noFile)) {
    Start-Sleep 2
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.