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
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.