批量循环不起作用。为什么?

时间:2014-05-18 10:36:28

标签: batch-file

我需要帮助来修复我的批次。

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  
) 

循环运行,但在第一行中,图像.jpg是真实的!任何想法???

1 个答案:

答案 0 :(得分:1)

您似乎错过了第一个/F循环中的FOR切换,即此行:

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

应该看起来像

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