

InterviewSolution
Saved Bookmarks
1. |
Solve : Convert Tiff file only if condition applies? |
Answer» <html><body><p>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.<br/><br/>Here's the scenario.<br/><br/>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 <a href="https://interviewquestions.tuteehub.com/tag/happen-1015459" style="font-weight:bold;" target="_blank" title="Click to know more about HAPPEN">HAPPEN</a> to be with the 'wrong' profile.<br/><br/>I'm <a href="https://interviewquestions.tuteehub.com/tag/confused-409756" style="font-weight:bold;" target="_blank" title="Click to know more about CONFUSED">CONFUSED</a> as to how the 'for' works, i'd like to get 'secondary' action in my for loop, but can't figure out how<br/><br/> Code: <a>[Select]</a>for /r %%a in (*.tif) do (identify -verbose "%%~<a href="https://interviewquestions.tuteehub.com/tag/fa0-456538" style="font-weight:bold;" target="_blank" title="Click to know more about FA">FA</a>" >> t.txt) <br/><br/>will print some info (using 'imagemagick') and somewhere in there should (or shouldn't) be a line with "<a href="https://interviewquestions.tuteehub.com/tag/adobe-12925" style="font-weight:bold;" target="_blank" title="Click to know more about ADOBE">ADOBE</a> RGB" in it<br/><br/>so I should add<br/><br/> Code: <a>[Select]</a>& if find "Adobe RGB" < (output of the 'identify' above)<br/><br/>or something that looks like it<br/><br/>then according to the result<br/><br/>do this:<br/><br/> Code: <a>[Select]</a>convert -profile AdobeRGB1998.icc -profile sRGB.icm %%a sRGB_%%~na.tif <br/><br/>Which is the only bit that I know works =)<br/><br/>If you can help me stitch the whole thing together, I'll give you a million internet hugs =)<br/><br/>Thanks and have a good day<br/><br/>BernieYou could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert<br/><br/> Code: <a>[Select]</a>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</p><blockquote>You could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert<br/><br/> Code: <a>[Select]</a>for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "sRGB_%%~na.tif" </blockquote> <br/>thanks, it does the trick!Ahah, so I have a little more <a href="https://interviewquestions.tuteehub.com/tag/work-20377" style="font-weight:bold;" target="_blank" title="Click to know more about WORK">WORK</a> 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!<br/><br/>Any ideas?<br/><br/> Code: <a>[Select]</a>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"<br/>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. <br/><br/><br/><br/> Quote<blockquote>I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop!</blockquote> <br/>But don't the converted files have a different profile? How do they get processed twice?</body></html> | |