So, after all the existing answers have not satisfied you, and you absolutely must skip in your batch file, I will try again:
@echo off setlocal for /f "delims=" %%f in ('dir /b /s batch') do call :DoSomething %%f goto end :DoSomething echo Here i am: %1 if %errorlevel%==1 goto :eof echo No error occured goto :eof :end endlocal
The trick is that the for loop calls a subfunction in the same file and provides the necessary parameter. This new call is made in a new context and can only access variables that are defined after do call :DoSomething in that order.
So, you need to access the variables here with %1 , %2 , etc. If you want to leave this context, you must have goto :eof to go to the end of the file (this marker is predefined in batch mode and should not appear in your file), which leaves the context and returns to the for loop.
After going through the whole cycle, we just go to the marker :end , clean it up a bit and finish it.
source share