Page 1 of 1

Scripting Trouble with long file name with spaces

Posted: 28 Oct 2010 06:51
by wowglide
Hi,

I am trying to make a command to use Image Magick command: convert <curpath> -resize 460 -quality 75 <curpath>\460px\%03d.jpg

I have tried putting quotation marks every which way around the run command and I just can't figure it out..

Anyone know how I would format the run command to run that string for folders with spaces in them like example if <curpath> was C:\Files and Images\Images by Size\ .. is there a curpath that shortens the path DOS style or am I just not formatting the string right?

I hope this makes sense

Thanks

Re: Scripting Trouble with long file name with spaces

Posted: 28 Oct 2010 18:54
by serendipity
Hi and Welcome,

I am not sure if its a mistake or you are trying something i don't know. You syntax starts with:
convert <curpath>

I think you have to also provide a file name to convert a file to something else.
Also, I think the below syntax should work for you if you change the paths accordingly. I tested this from by copy/pasting the code into Scripting>Try script:

Code: Select all

//ImageMagick script to convert selected image to new.jpg
   focus;
   run "cmd /k cd /d C:\Program Files\ImageMagick\ & convert <curitem> -quality 75 -resize 460 <curpath>\new.jpg"
hope that helps.

Re: Scripting Trouble with long file name with spaces

Posted: 28 Oct 2010 19:25
by wowglide
serendipity wrote:Hi and Welcome,

I am not sure if its a mistake or you are trying something i don't know. You syntax starts with:
convert <curpath>

I think you have to also provide a file name to convert a file to something else.
Also, I think the below syntax should work for you if you change the paths accordingly. I tested this from by copy/pasting the code into Scripting>Try script:

Code: Select all

//ImageMagick script to convert selected image to new.jpg
   focus;
   run "cmd /k cd /d C:\Program Files\ImageMagick\ & convert <curitem> -quality 75 -resize 460 <curpath>\new.jpg"
hope that helps.
Oops, I worded my command wrong here is the correct one:

convert <curpath>\*.jpg -resize 460 -quality 75 <curpath>\460px\%03d.jpg

this makes the image magick convert.exe convert all JPEGs in the current directory then the %03d.jpg is just to incremental number them, does this make sense? I think the whole \*.jpg is what is throwing off my syntax

Re: Scripting Trouble with long file name with spaces

Posted: 28 Oct 2010 19:39
by admin
I surely can be done, but I have to know what syntax is expected by ImageMagick. Can you give a wellformed example?

Re: Scripting Trouble with long file name with spaces

Posted: 28 Oct 2010 19:47
by serendipity
wowglide wrote:Oops, I worded my command wrong here is the correct one:

convert <curpath>\*.jpg -resize 460 -quality 75 <curpath>\460px\%03d.jpg

this makes the image magick convert.exe convert all JPEGs in the current directory then the %03d.jpg is just to incremental number them, does this make sense? I think the whole \*.jpg is what is throwing off my syntax
Oh ok, this should work (tested it myself):

Code: Select all

//Converts all jpgs in current folder to 000.jpg, 001.jpg and so on.    
    focus;
    run "cmd /k cd /d C:\Program Files\ImageMagick\ & convert <curpath>\*.jpg -quality 75 -resize 460 <curpath>\%03d.jpg"
Good luck.

Re: Scripting Trouble with long file name with spaces

Posted: 29 Oct 2010 05:08
by wowglide
serendipity wrote:
wowglide wrote:Oops, I worded my command wrong here is the correct one:

convert <curpath>\*.jpg -resize 460 -quality 75 <curpath>\460px\%03d.jpg

this makes the image magick convert.exe convert all JPEGs in the current directory then the %03d.jpg is just to incremental number them, does this make sense? I think the whole \*.jpg is what is throwing off my syntax
Oh ok, this should work (tested it myself):

Code: Select all

//Converts all jpgs in current folder to 000.jpg, 001.jpg and so on.    
    focus;
    run "cmd /k cd /d C:\Program Files\ImageMagick\ & convert <curpath>\*.jpg -quality 75 -resize 460 <curpath>\%03d.jpg"
Good luck.
It craps out when the <curpath> returns a long path with spaces, example <curpath> returns C:\My Pictures\Tuesday Album\ .. cmd doesn't like spaces, How do I add quotes around the path, I tried the double quotes around it but it errors out.

Re: Scripting Trouble with long file name with spaces

Posted: 29 Oct 2010 06:51
by serendipity
wowglide wrote:
serendipity wrote:
wowglide wrote:Oops, I worded my command wrong here is the correct one:

convert <curpath>\*.jpg -resize 460 -quality 75 <curpath>\460px\%03d.jpg

this makes the image magick convert.exe convert all JPEGs in the current directory then the %03d.jpg is just to incremental number them, does this make sense? I think the whole \*.jpg is what is throwing off my syntax
Oh ok, this should work (tested it myself):

Code: Select all

//Converts all jpgs in current folder to 000.jpg, 001.jpg and so on.    
    focus;
    run "cmd /k cd /d C:\Program Files\ImageMagick\ & convert <curpath>\*.jpg -quality 75 -resize 460 <curpath>\%03d.jpg"
Good luck.
It craps out when the <curpath> returns a long path with spaces, example <curpath> returns C:\My Pictures\Tuesday Album\ .. cmd doesn't like spaces, How do I add quotes around the path, I tried the double quotes around it but it errors out.
Sorry, I am bad at quoting myself.
This worked for me (I also double quoted the ImageMagick path)

Code: Select all

//Converts all jpgs in current folder to 000.jpg, 001.jpg and so on.   
    focus;
    run "cmd /k cd /d ""C:\Program Files\ImageMagick\"" & convert ""<curpath>\*.jpg"" -quality 75 -resize 460 ""<curpath>\%03d.jpg"""

Re: Scripting Trouble with long file name with spaces

Posted: 29 Oct 2010 07:31
by wowglide
serendipity wrote:
wowglide wrote:
serendipity wrote:
wowglide wrote:Oops, I worded my command wrong here is the correct one:

convert <curpath>\*.jpg -resize 460 -quality 75 <curpath>\460px\%03d.jpg

this makes the image magick convert.exe convert all JPEGs in the current directory then the %03d.jpg is just to incremental number them, does this make sense? I think the whole \*.jpg is what is throwing off my syntax
Oh ok, this should work (tested it myself):

Code: Select all

//Converts all jpgs in current folder to 000.jpg, 001.jpg and so on.    
    focus;
    run "cmd /k cd /d C:\Program Files\ImageMagick\ & convert <curpath>\*.jpg -quality 75 -resize 460 <curpath>\%03d.jpg"
Good luck.
It craps out when the <curpath> returns a long path with spaces, example <curpath> returns C:\My Pictures\Tuesday Album\ .. cmd doesn't like spaces, How do I add quotes around the path, I tried the double quotes around it but it errors out.
Sorry, I am bad at quoting myself.
This worked for me (I also double quoted the ImageMagick path)

Code: Select all

//Converts all jpgs in current folder to 000.jpg, 001.jpg and so on.   
    focus;
    run "cmd /k cd /d ""C:\Program Files\ImageMagick\"" & convert ""<curpath>\*.jpg"" -quality 75 -resize 460 ""<curpath>\%03d.jpg"""
Works! Thanks so much for your help, I worked on it for a hour or so last night trying to get it to work lol