Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

if errorlevel goto next iteration of for loop

2,438 views
Skip to first unread message

andy

unread,
May 6, 2007, 4:52:20 PM5/6/07
to
for eg:

for /f %%i in ('dir /b *.html') do (
<execute some command on each html file>
)

in case of error (Do you wish to continue [Y/N] message how do i do an
equivalent of "continue" in batch scripting.

i could do something like this after the command statement inside the
loop:
if errorlevel 1 goto start (where start is label before the command
statment)
will this make the loop variable to skip to the next value??
also does the label need to be before 'do' or before the first
statement in the do loop??

any help would be greatly appreciated.

THanks.

Matthias Tacke

unread,
May 6, 2007, 5:43:16 PM5/6/07
to
andy wrote:
> for eg:
>
> for /f %%i in ('dir /b *.html') do (
> <execute some command on each html file>
> )
>
> in case of error (Do you wish to continue [Y/N] message how do i do an
> equivalent of "continue" in batch scripting.
>
> i could do something like this after the command statement inside the
> loop:
> if errorlevel 1 goto start (where start is label before the command
> statment)
You are a bit vague here. Which command?

> will this make the loop variable to skip to the next value??
> also does the label need to be before 'do' or before the first
> statement in the do loop??
>

No, the for in do is fixed. Maybe a different construct fits better.

You can call a sub routine in the do part and exit at different points or
work with conditional execution || resp. && based on errors.

@echo off
for /f %%i in ('dir /b *.html') do call :sub "%%i"
goto :eof
:sub
REM in the sub the passed argument (%%i) is %1
:: execute some command on each html file

if errorlevel 1 echo an error occured&goto :eof
:: execute some other commands
goto :eof

--
Greetings
Matthias

0 new messages