0

I am having a batch file, in that i want to block untill a file gets generated. I got a sample script on bash script. How we can do the same thing in batch script.

1 Answer 1

0

This is the usual way of doing it.

@echo off
    setlocal enableextensions

    set "flagFile=c:\somewhere\list.txt"

:loop
    if not exist "%flagFile%" (
        ping -n 2 localhost > nul
        goto loop
    )

    echo File %flagFile% exists

    endlocal

For a non goto version

@echo off
    setlocal enableextensions

    set "flagFile=c:\somewhere\list.txt"
    (cd.|for /l %%a in (0 0 1) do @(dir "%flagFile%">nul 2>nul && exit || ping -n 2 localhost > nul ))

    echo File %flagFile% exists

    endlocal

This spawns a separate copy of cmd that will loop until the file exists, with a 1 second pause between checks.

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.