Scripting Trouble with long file name with spaces

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
wowglide
Posts: 4
Joined: 28 Oct 2010 06:47

Scripting Trouble with long file name with spaces

Post 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

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Scripting Trouble with long file name with spaces

Post 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.

wowglide
Posts: 4
Joined: 28 Oct 2010 06:47

Re: Scripting Trouble with long file name with spaces

Post 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

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Scripting Trouble with long file name with spaces

Post by admin »

I surely can be done, but I have to know what syntax is expected by ImageMagick. Can you give a wellformed example?

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Scripting Trouble with long file name with spaces

Post 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.

wowglide
Posts: 4
Joined: 28 Oct 2010 06:47

Re: Scripting Trouble with long file name with spaces

Post 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.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Scripting Trouble with long file name with spaces

Post 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"""

wowglide
Posts: 4
Joined: 28 Oct 2010 06:47

Re: Scripting Trouble with long file name with spaces

Post 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

Post Reply