I have a directory with two sets of images. The postfix of these files are matched in pairs, such as Top_0001.png,Top_0002.png,Bottom_0001.png,Bottom_0002.png. The output of these four files should be Combined_0001 and Combined_0002.
In reality, the postfix is random and there will be several thousand files to process.



What would be the easiest way to append these images in a batch file? I have managed to google together something that works, but I do not quite understand WHY and HOW it works. Any comments are appreciated.
Code: Select all
@echo off
:: setLocal EnableDelayedExpansion
set targetdir="C:\temp"
set setnum=0
for /f "tokens=2 delims=_." %%a in ('dir /b /o-n %targetdir%\Top*.png') do convert %targetdir%\Top_%%a.png %targetdir%\Bottom_%%a.png -append %targetdir%\Combined_%%a.png