do {} until ($false) is an infinite loop; it’ll only exit if you use something like break, return or throw from inside the loop body. do { } until ($true) would execute the loop body exactly once (which would make the loop rather pointless.)
It looks like what you intended to do was wait for a file to exist. For that, the code would look something like this:
while (-not (Test-Path d:\test\test.log))
{
Start-Sleep -Milliseconds 100
}
# Do something with d:\test\test.log
I used a while loop instead of a do loop here, but the idea is the same; the loop condition is the result from Test-Path. I highly recommend putting a small sleep statement inside the loop body, as I’ve done here, so you don’t just spin needlessly. A tenth of a second isn’t much time in terms of user experience, but makes a massive difference to how fast you’re banging away on the disk or CPU.
With the while statement (or loop), the loop only runs if the condition evaluates to true.
A do-until loop checks the condition at the bottom of the loop, runs at least once, and is designed to continue as long as the condition is false. A do-while loop is similar to a do-until loop but repeats as long as the condition is true.
I modified my previous code to reverse the condition but it appears that it will not work because the loop only runs once and doesn’t continue to test the condition to see if the file exists or not: