tags:

views:

29

answers:

2

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 file to continue its attempts until it has a success. How can i do that?

+3  A: 
goto :foo2
:foo
sleep 1
:foo2
del file
if exist file goto :foo
jeffamaphone
Your users will hate you for using so much CPU
Earlz
+1 to the answer because it's correct. +1 to @Earlz because he's also correct. Perhaps a sleep command will help. That or running the batch file at a lower priority.
afrazier
Well, okay, I assumed this was for your own personal machine in the course of development. You shouldn't ship this.
jeffamaphone
Note: I edited your answer. You may want to rollback or tweak it to your liking. Anyways, good answer.
acidzombie24
ping'ing localhost is probably the best way to sleep on NT systems, on 9x you also have choice.com
Anders
A: 

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.

mr.b