create loop in batch for multiple export with ImageMagick

微笑、不失礼 提交于 2019-12-25 03:45:27

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/15807586/create-loop-in-batch-for-multiple-export-with-imagemagick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!