0

I am trying to build a Windows batch file which should do the following:

  • Take the reference image (it should be the first image by taking into account the numeration ima_0001.png, ima_0002.png...).
  • In the second step, the FOR structure takes the images in the sequence (e.g.: ima_0001.png, imag_002.png, ...), calls a function to compare images from another batch file, and updates the reference image with the current image %defa%.

The script performs nearly well except for two major steps:

  1. I can't set the reference or first file directly with set "defa=ima_0001.png"
    I tried in different ways: defa=ima_0001.png, defa=!ima_0001.png!, without success.
    So finally I decided to leave the FOR structure selecting one which does not coincide with the first numbered (it takes ima_0064.png and not ima_0001.png)
    I thank somebody who can help me to set the first one whether manually or automatically.

  2. The worst part is that the second FOR structure does not change the reference image with the line set "defa=%%h".
    For example, after the first cycle FOR, defa should change from ima_0001.png to ima_0002.png, or from ima_0064.png to ima_0065.png. However, when console runs, %%h changes, but defa always shows the first image, (ima_0064.png). I also tried different ways without success, as well as setting setlocal or not setting it.
    I thank somebody who can give me notions to solve his issue.

The script is:

@echo off
setlocal enabledelayedexpansion
cd C:\Users\docs

set/a "th=870"
REM Set the first file or take one with FOR 
::set "defa=ima_0001.png"
FOR %%m in (1,1,*.png) do set "defa=%%m"
REM BUCLE DE LLAMADA A LA FUNCIÓN Callme
FOR %%h in (*.png) DO (
    Callme "%defa%" "%%h" %th%
    set "defa=%%h"
)
pause
Compo
  • 36,585
  • 5
  • 27
  • 39
  • 2
    `FOR %%m in (1,1,*.png) do` - it looks like you mixed the syntaxes for a pur `for` and a `for /L` to get the first (alphabetical) file: `for /f "delims=" %%m in ('dir /b /on') do if not defined defa set "defa=%%m"` (be sure `defa` is undefined before entering the loop) – Stephan Nov 14 '20 at 12:38
  • Thank you Stephan. Now the first value of defa is just the first file ima_ooo1.png – user3265206 Nov 14 '20 at 22:13
  • What is `Callme`? An application (.exe)? Another batch script? – Stephan Nov 14 '20 at 22:18
  • Thank you Stephan. Now the first file coincided with the first one in the numeric order, although I have a new problem that I'll post in a new question. – user3265206 Nov 14 '20 at 22:20
  • Yes, Callme is a function another batch file that apply to the file parsed by the second for structure. – user3265206 Nov 14 '20 at 22:21
  • batchfiles have to be `call`ed, else they don't return: `call callme.bat "!defa!" "%%h" %th%` – Stephan Nov 14 '20 at 22:32

0 Answers0