gerry_76
gerry_76

Reputation: 158

Batch Loop doesn't work. Why?

I need help to fix my batch.

setlocal EnableDelayedExpansion
rem Get existent *.jpg files and sort they in the right order
for %%a in ('dir /b /a-d "%sourcedir%\*.jpg" ') do (
   set /A seq=1000000001+%%~Na
   set file[!seq!]=%%a
)
rem Generate div containers with groups of 5 files each
set i=0
(for /F "tokens=2 delims==" %%a in ('set file[') do (
   set /A i+=1, iMOD5=i %% 5
   if !iMOD5! equ 1 (
      rem break point block <div container> open
      ECHO ^<div class="gallery-row"^>
   )
   ECHO ^<div^>^<a href='images/%%~NXa'^>^<img src='images/%%~NXa' /^>^</a^>^</div^>

   if !iMOD5! equ 0 (
      rem break point block </div container> closed
      echo ^</div^>
   )
)) >>%page%.html
rem Close the last div container, if any
if %iMOD5% neq 0 (
   echo ^</div^> >>%page%.html  
) 

The cycle run, but in the first line the image .jpg is emplty!!! Any idea???

Upvotes: 0

Views: 177

Answers (1)

Luke Woodward
Luke Woodward

Reputation: 64949

It looks like you've missed the /F switch from the first FOR loop, i.e. this line:

for %%a in ('dir /b /a-d "%sourcedir%\*.jpg" ') do (

It should look like

for /F %%a in ('dir /b /a-d "%sourcedir%\*.jpg" ') do (

Upvotes: 1

Related Questions