title: How can I check if I am at EOF when reading a file from a CMD Batch.bat?
body: <p>I'm trying to fill X files with chunks of content from a .txt file.
  The thing is the .txt (source) file is small and I want my code to loop over it's content chunk by chunk and start again when no more chunks are avaliable until all files have been filled.</p>
  
  <p>This is part of the (still on development) code. I've managed to teach my Batch.bat to recognized the chunks but I don't know how to check if I am at EOF to go back again to the begining.</p>
  
  <p>Current code doesn't work since it has been simplified for the question (delayed expansion not present)</p>
  
  <pre><code>SET /A J=1
  FOR /F "skip=%J% tokens=*" %%A IN (%~1%) DO ( 
   CALL :CSV "%%A" %J%
  )
  EXIT /B
  :CSV
  SETLOCAL
  IF NOT "%~1"=="---" ( 
   ECHO %~1 &gt;&gt; Chistaco.txt
  )
  ENDLOCAL &amp;&amp; SET /A J=%2+1
  </code></pre>
  
  <p>Code posted here is just a guide of my target, don't miss the question.</p>
  
  <p>Thank you !</p>
  
  <p>EDIT: Simplified Code Module</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL
  
  REM Ask for parameters
  SET /P filler=Enter the name of the file to use as filler (file.ext): 
  SET /P seed=Enter the seed of the files to fill: 
  CLS &amp;&amp; ECHO %~1%
  
  REM The variable "J" counts the lines to jump in "file.ext" (and btw, it cannot be 0 as the batch parses fails to read it)
  REM This is where the EOF check is needed: "J" must be referenced outside the main loop so the script can loop inside "file.ext" untill all "seed???" files have been filled
  SET /A J=1
  FOR /R "%path%" %%X IN (%seed%*) DO ECHO %%X &amp;&amp; CALL :FillerChomper "%filler%" "%%X"
  ENDLOCAL
  EXIT /B
  
  :FillerChomper
  SETLOCAL
  FOR /F "skip=%J% tokens=*" %%A IN (%~1%) DO ( 
   CALL :CSV "%%A" J %2%
   IF "%%A"=="---" EXIT /B
  )
  EXIT /B
  
  :CSV
  SETLOCAL
  IF NOT %1=="---" ECHO %~1 &gt;&gt; %~3%
  ENDLOCAL &amp;&amp; SET /A %2=%J%+1
  EXIT /B
  REM All functions must have a "EXIT /B" command or batch will just keep executing codelines until :EOF
  </code></pre>
  
  <p>Thank you guys for your help!</p>