bat file. delete until success?
I run a bat file to clean up and sometimes it takes a few seconds for my app to full close. In it i delete a database. Instead of waiting or running it multiple times i would like the bat fi开发者_StackOverflowle to continue its attempts until it has a success. How can i do that?
goto :foo2
:foo
sleep 1
:foo2
del file
if exist file goto :foo
In this code, you rely on the fact that your command sets non zero error level if (when) it fails. And you know which error code it sets.
Something along the lines of
@echo off
:Delete
deletedatabasecommand
if ERRORLEVEL 123 GOTO Delete
That should do it.
精彩评论