danielassayag
danielassayag

Reputation: 931

create loop in batch for multiple export with ImageMagick

Im trying to make a batch file that process multiple image files.

The files are named P_1316_0001.png P_1316_0002.png P_1316_0003.png etc.. LETs sqy P_1316 is VARSESSION) thanks to the ImageMagick program i can convert an image directly with batch.

Basically what i want to do is :

Create a variable that would increment until there is no more file to convert in the folder. Comvert the file from png to jpg (convert %VARSESSION%%i%.png %VARSESSION%%i%.jpg) assuming that i is 0001

Well i hope you can help me. i thank you

Daniel

Upvotes: 0

Views: 1190

Answers (1)

Magoo
Magoo

Reputation: 80033

You're being a little restrictive with your question, but to suit the precise parameters you've specified,

SETLOCAL ENABLEDELAYEDEXPANSION
for /l %%i in (10001,1,19999) do (
 set numb=%%i
 ECHO if exist %varsession%_!numb:~1!.png convert %varsession%_!numb:~1!.png %varsession%_!numb:~1!.jpg
)
ENDLOCAL

But there are much better ways, such as

for /f %%i in ('dir /b /a-d %varsession%_*.png') do (
ECHO convert %%i %%~ni.jpg
)

Assuming that all files matching %varsession%_*.png are to be processed.

Note: keyword ECHO inserted to SHOW what the batch proposes to do. Remove the ECHO to actually perform the action

Upvotes: 1

Related Questions