Jump to content

BATCH - loop performs twice

Dogway
Go to solution Solved by Dogway,

I guess so. I will do that then.

 

edit: I just created a folder, moved back and deleted. Hacky but works.

 

md "%foldername%"

move /y "%foldername%\*.*" "./"
rd /s /q "%foldername%"

Hello, I have made a script to encode images in one folder.

The problem is that for some reason when input format is not the same as output format the loop applies to the new created file as well, hence creating 2 output files for the same input file. I'm not sure, I thought "FOR %%I" gets validated at parse time.

SET mSize=50%%SET outputformat=pngSET linear=trueIF %linear% EQU true (goto linear)IF %outputformat% NEQ "png" (SET Encode=-quality 90) ELSE (SET Encode=-compress Lossless png:compression-level=9) :linearECHO.ECHO Creating the Down-sampled image with output sharpening, please wait ...FOR %%I IN ( *.jpg, *.jpeg, *.png, *.tif, *.tiff, *.bmp ) do convert -quiet "%%~nxI" -filter Spline -distort resize ^%mSize% -colorspace sRGB %Encode% "%%~nI_New.%outputformat%"
Link to comment
Share on other sites

Link to post
Share on other sites

Why don't you just take ".png" out of the input file list? Unless you needed to compress I don't see you you'd need to do this.

If you found my post helpful make sure to press the "Like This" Button  ;)

Link to comment
Share on other sites

Link to post
Share on other sites

I don't get your point. If I take out .png as input then I won't be able to process png files...

Link to comment
Share on other sites

Link to post
Share on other sites

The *.xxx get done separately, it does all the loops for *.jpg then calculates and loops for *.jpeg then the next thing and so on.  You should be able to fix it by putting *.png as the first type. But of course if you ever change the output format it will break again so I'm not really sure about a permanent solution.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

I see, so that's how it works as I feared. I also thought about how to deal with this, I thought on first detecting the input extension and adding it as an exclusion to the "FOR" command. But I'm not sure how I can parse input extension without a FOR call...

If any I might do this in AHK. I always crash on trying to do things in BATCH  :(

Link to comment
Share on other sites

Link to post
Share on other sites

I guess so. I will do that then.

 

edit: I just created a folder, moved back and deleted. Hacky but works.

 

md "%foldername%"

move /y "%foldername%\*.*" "./"
rd /s /q "%foldername%"

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×