Loop question in DOS scripts

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
test84

Loop question in DOS scripts

Post by test84 »

Hi,

I'm trying to loop through two sets of files to pass them to ImageMagick in order to generate my result files. The challenge is how to read two files in my loop, as far as I went through, I can only loop through one set of files.

Here is concept of what I'm gonna do:

FOR %%a in (*.jpg)
DO FOR %%b in (*.bat)
convert %%a %%b -compose copy_opacity -composite %%result

Hence I donno how to set third file name.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Loop question in DOS scripts

Post by el_supremo »

If the combination of names in %%a and %%b is unique you could use that to create a new filename.
E.g. if %%a is "fred.jpg" and %%b is "whatever.png" you could create the name fred_whatever.gif (for example) using this kind of syntax:

Code: Select all

convert %%a %%b -compose copy_opacity -composite %%~na_%%~nb.gif
There is a description of %%~n and other tricks near the bottom of this page:
http://www.computerhope.com/forhlp.htm

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
test84

Re: Loop question in DOS scripts

Post by test84 »

el_supremo wrote:If the combination of names in %%a and %%b is unique you could use that to create a new filename.
E.g. if %%a is "fred.jpg" and %%b is "whatever.png" you could create the name fred_whatever.gif (for example) using this kind of syntax:

Code: Select all

convert %%a %%b -compose copy_opacity -composite %%~na_%%~nb.gif
There is a description of %%~n and other tricks near the bottom of this page:
http://www.computerhope.com/forhlp.htm

Pete
Thank you for the answer, but I can't assign %%a and %%b in DOS, I can only set one variable per FOR loop, where in this case we need two parameters for FOR loop.

And when I do something like this

Code: Select all

FOR %%a in (FIR_026?.jpg) DO FOR %%b in (FIR_026M?.jpg) DO  imconvert %%a %%b -compose copy_opacity -composite %%~na_%%~nb.png

So we have to traverse once with a one for loop.
it will do the Cartesian product and generate like 16 files instead of 4.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Loop question in DOS scripts

Post by anthony »

Also see... Usign IM from Windows Batch Scripts...
http://www.imagemagick.org/Usage/windows/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
test84

Re: Loop question in DOS scripts

Post by test84 »

Thank you, I could manage it all with Python.
Post Reply