Page 1 of 1

Create Directory if One Does Not Exist

Posted: 2014-04-19T10:22:57-07:00
by holden
It looks like IM won't create a directory, or do anything, if there is a directory name in the command. Eg.

Code: Select all

Convert image.jpg -size 800x1000 C:\home\NewFolder\image.jpg 
If NewFolder doesn't exist then IM acts like it does something but the rendered image or new dir doesn't exist. Is there a way to make IM create a directory if one doesn't exist already, otherwise save into one that does exist already?

Re: Create Directory if One Does Not Exist

Posted: 2014-04-19T10:54:54-07:00
by fmw42
As far as I know, IM will not create a new directory. I think one has to use the OS to script a test if the directory exists or not. Then if not create one. Or decide to use some other default directory. At least I think this is how it works in Unix. I do not know much about Windows.

Re: Create Directory if One Does Not Exist

Posted: 2014-04-19T10:59:50-07:00
by snibgo
I suppose you are on Windows. What version of IM?

When I try this on IM v6.8.9-0 on Windows 8.1, I get ...

Code: Select all

F:\web\im>%IM%convert rose: newdir\r.png

convert.exe: unable to open image `newdir\r.png': No such file or directory @ error/blob.c/OpenBlob/2647.
convert.exe: WriteBlob Failed `newdir\r.png' @ error/png.c/MagickPNGErrorHandler/1806.
... which is fair enough.

AFAIK IM won't create directories. If it can't create a file it won't try again somewhere else.

You can:

Code: Select all

if not exist newdir md newdir