I\'ve written the following batch file to create multiple files using FOR loop:
@echo off cls FOR /L %%i IN (1 1 10) DO ( echo.> file%%i.txt
Like adarshr said, the second FOR loop can find even the new created files.
You can avoid this by using FOR/F with a command, as the result of the dir is completely fetched before the body of the loop is executed.
...
FOR /F "delims=" %%i IN ('dir /b *.txt') DO (
echo.> file%%i.txt
IF ERRORLEVEL 0 echo Successfully created file 'file%%i.txt'.
)