1.

Solve : Convert Tiff file only if condition applies?

Answer»

Hello fellow msdos coders, I wish I could do this with python or some other uncluttered language, but it has to be dos... I thank you in advance for any input.

Here's the scenario.

I have a large number of Tiff image files in folders and subfolders, and I need to convert them to a different color profile ONLY if they HAPPEN to be with the 'wrong' profile.

I'm CONFUSED as to how the 'for' works, i'd like to get 'secondary' action in my for loop, but can't figure out how

Code: [Select]for /r %%a in (*.tif) do (identify -verbose "%%~FA" >> t.txt)

will print some info (using 'imagemagick') and somewhere in there should (or shouldn't) be a line with "ADOBE RGB" in it

so I should add

Code: [Select]& if find "Adobe RGB" < (output of the 'identify' above)

or something that looks like it

then according to the result

do this:

Code: [Select]convert -profile AdobeRGB1998.icc -profile sRGB.icm %%a sRGB_%%~na.tif

Which is the only bit that I know works =)

If you can help me stitch the whole thing together, I'll give you a million internet hugs =)

Thanks and have a good day

BernieYou could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert

Code: [Select]for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "sRGB_%%~na.tif" Quote from: Salmon Trout on September 28, 2010, 11:29:06 AM

You could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert

Code: [Select]for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "sRGB_%%~na.tif"

thanks, it does the trick!Ahah, so I have a little more WORK on that script, right now it works, but instead of using a prefix, I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop!

Any ideas?

Code: [Select]for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB (1998)" &&  mkdir "%%~pa/sRGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "%%~pa/sRGB/%%~na.tif"
Copy them into a folder outside the tree being walked by FOR /R, or instead of FOR /R you can use FOR /F to parse the output of 'dir /b /s *.tif', use %%~pa to identify those tifs not in the converted folder, which you convert and move.



Quote
I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop!

But don't the converted files have a different profile? How do they get processed twice?


Discussion

No Comment Found