Folder path syntax

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mikelee33
Posts: 3
Joined: 2017-11-27T15:31:14-07:00
Authentication code: 1152

Folder path syntax

Post by mikelee33 » 2017-11-28T10:53:07-07:00

Hello -

I'm a new ImageMagick user. The one thing I am wanting to do with ImageMagick is giving me problems, and I'm certain it's a syntax error. I have no problems processing single files using "convert", but attempting to correctly specify explicit paths to source and output folders, in order to process entire folders (and repeatedly failing), has led me to ask for assistance.

For my application I am required to specify the full paths to the source and output folders. I've tried numerous variations on this, substituting "*.JPG" with "*.*" or removing it completely:

convert "C:\Users\DELL\Desktop\test\*.JPG" -pointsize 30 -background black -fill white label:@comment.txt -gravity center -append "C:\Users\DELL\Desktop\test\output\*.JPG"

The "output" folder exists in the "test" folder, and "convert.exe" is in the path. Again, single files are no problem, just getting the syntax to specify folder processing is.

Many thanks,
Mike

IM 7.0.6-10 Q16 x86
Windows 10 Pro

User avatar
GeeMack
Posts: 629
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Folder path syntax

Post by GeeMack » 2017-11-28T13:40:40-07:00

mikelee33 wrote:
2017-11-28T10:53:07-07:00
For my application I am required to specify the full paths to the source and output folders. I've tried numerous variations on this, substituting "*.JPG" with "*.*" or removing it completely:

convert "C:\Users\DELL\Desktop\test\*.JPG" -pointsize 30 -background black -fill white label:@comment.txt -gravity center -append "C:\Users\DELL\Desktop\test\output\*.JPG"

The "output" folder exists in the "test" folder, and "convert.exe" is in the path. Again, single files are no problem, just getting the syntax to specify folder processing is.
I can think of at least one way IM7 can do that without relying on other outside commands, but it's probably less complicated to just work that process in a "for" loop. A tiny BAT script might look something like this...

Code: Select all

@echo off

for %%I in ( C:\Users\DELL\Desktop\test\*.JPG ) do (
   convert "%%I" -pointsize 30 -background black -fill white ^
      label:@comment.txt -gravity center -append "C:\Users\DELL\Desktop\test\output\%%~nxI"
)

echo Done.
Save it as a *.bat file and run it in the same directory as your "comment.txt". If you're running from a command prompt instead of a BAT script, a similar command would use single percent signs "%" instead of doubles "%%".

mikelee33
Posts: 3
Joined: 2017-11-27T15:31:14-07:00
Authentication code: 1152

Re: Folder path syntax

Post by mikelee33 » 2017-11-28T15:17:51-07:00

GeeMack -

Thank you very much for your response, example, and suggestion.

Yes, if I could incorporate all this into a "for' loop in a BAT script I definitely would, although my need is to furnish an "explicit" path, as I am working with variables in an AutoIt script. If I could figure out the logic behind how IM sees and works with folders then I would be all set and could proceed. The thing is IM seems to work with folders quite differently from files. Is this early observation true?

The command line example I furnished earlier is essentially how I would code it in AutoIt, where the full paths are replaced with variables:

RunWait(@ComSpec & " /c " & $PROG & ' "' & GUICtrlRead($FILE) & "\*.JPG" & '"' & " -pointsize 30 -background black -fill white " & "label:@comment.txt" & " -gravity center -append" & ' "' & GUICtrlRead($FILE) & "\output\*.JPG" & '"', "", @SW_HIDE)

Where $PROG = convert.exe

I apologize for bringing another scripting language into this discussion, but essentially it all comes down to how IM needs the output folder and files defined (as I interpret your batch script).

Thanks again

snibgo
Posts: 10707
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Folder path syntax

Post by snibgo » 2017-11-28T15:40:14-07:00

The easiest way to use "convert" is with one file at a time: one input file that converts to one output file. And you need to give the full path to each. No wildcards.

GeeMack has showed how to do that in Windows BAT scripts: the shell script loops through files, calling "convert" for each one.

I'm not familiar with AutoIt, but I expect is has a mechanism to loop through files.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 23854
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Folder path syntax

Post by fmw42 » 2017-11-28T15:59:04-07:00

You cannot use wildcards for both input and output with magick/convert. To process a folder of images, you need to use magick mogrify in IM 7 (or just mogrify in IM 6)

cd to directory

Code: Select all

magick mogrify -path path2/existing/folder -format jpg *
will convert every image in the directory to the same name with jpg suffix and put it in path2/existing/folder

see http://www.imagemagick.org/Usage/basics/#mogrify

mikelee33
Posts: 3
Joined: 2017-11-27T15:31:14-07:00
Authentication code: 1152

Re: Folder path syntax

Post by mikelee33 » 2017-11-28T18:05:25-07:00

Thank you all.

Even though in my intended use and example I wanted to use -append, and that operator is not available for use with mogrify, I have found that I can substitute -annotate to get the information I need onto photos if it means that I can be more easily accomplish my folder processing.

Thanks again for pointing me in a more workable direction.

Post Reply