Page 1 of 1

Need help with looping over directories

Posted: 2014-05-12T11:32:34-07:00
by seanspotatobusiness
Could someone provide the code for looping through directories? I'd like to convert my (40 GB total!) uncompressed TIFFs to LWZ-compressed TIFFs but maintaining directory structure/hierarchy.

Re: Need help watermarking images in Image Magick!

Posted: 2014-05-12T11:34:17-07:00
by fmw42
seanspotatobusiness wrote:Could someone provide the code for looping through directories? I'm in a similar situation with respect to maintaining directory structure/hierarchy except I want to convert my (40 GB total!) uncompressed TIFFs to LWZ-compressed TIFFs.
Code depends upon your OS (Windows or Unix)? Also what version of IM are you using?

In the future, please start a new topic rather than tacking onto an old one. Also please read viewtopic.php?f=1&t=9620

Re: Need help with looping over directories

Posted: 2014-05-13T02:43:21-07:00
by seanspotatobusiness
I'm using Windows 7 and ImageMagick version is 6.8-7.6 Q16 x64 2013-11-07.

I thought my query was still relevant to the older thread because although the solution of looping over directories was mentioned, there was no indication of how that should be done.

Re: Need help with looping over directories

Posted: 2014-05-13T03:58:02-07:00
by snibgo
IM contains a "mogrify" command for processing multiple files files in one directory, but it won't walk a directory tree. So you need to use an operating system facility for that.

I would use "for" to get individual files, and "convert" to convert one at a time. Type "for /?" for help. For example, at the command line:

Code: Select all

for /F %F in ('dir /b /s *.tiff') do echo %~dpF %~nF
Instead of echo, you would have a convert command, which would depend on exactly what you want to do. For example "convert %F -compress LZW %F" would compress each file, overwriting it. You might prefer to create copies in a separate directory structure.