Page 1 of 1
Loop question in DOS scripts
Posted: 2009-05-27T10:25:47-07:00
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.
Re: Loop question in DOS scripts
Posted: 2009-05-27T11:36:24-07:00
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
Re: Loop question in DOS scripts
Posted: 2009-05-28T03:19:05-07:00
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.
Re: Loop question in DOS scripts
Posted: 2009-05-31T21:34:17-07:00
by anthony
Also see... Usign IM from Windows Batch Scripts...
http://www.imagemagick.org/Usage/windows/
Re: Loop question in DOS scripts
Posted: 2009-06-01T03:47:38-07:00
by test84
Thank you, I could manage it all with Python.