Page 1 of 1

filenames with blanks in User Button script

Posted: 09 Oct 2012 01:05
by jd
I am trying to set up a User Button so that it will run a command (let's call it MyEditor.exe for this discussion) with the currently selected filename as an argument.

I have set the on click action to be:

Code: Select all

    run "c:\path\to\MyEditor.exe <curitem>"
but if there are blanks in the file name, this causes confusion. What's the proper way to quote things so that the blanks don't cause the argument to be treated as multiple arguments?

Thanks...

-- jeff

Re: filenames with blanks in User Button script

Posted: 09 Oct 2012 01:15
by highend

Code: Select all

run """c:\path\to\MyEditor.exe"" ""<curitem>"""; 

Re: filenames with blanks in User Button script

Posted: 09 Oct 2012 01:17
by nas8e9
From XYplorer's help file:
Using Quotes in Scripting

It's strongly recommended that you (double- or single-) quote your strings! While the script engine is currently still permissive with unquoted strings (msg Hi! works) this might not be so in the future, so you better do msg "Hi!" right away!

Here's the basic laws of quoting:

(1) Everything is either in double-quotes, or in single-quotes, or outside of any quotes.

(2) To have double-quotes inside double-quotes they must be doubled.

(3) To have single-quotes inside single-quotes they must be doubled.

(4) Variables are resolved in double-quotes and outside of any quotes, but not in single-quotes.
Assuming "c:\path\to\MyEditor.exe" contains a space (it would have been helpful to see the exact command; scripting can go wrong with a single character wrong or missing somewhere), you'd need to additionally double-quote it like so:

Code: Select all

run """c:\path\to\MyEditor.exe"" ""<curitem>"""
Edited to add: I see that highend has provided the same answer with additionally <curitem> double-quoted; I'm guessing that this is to do with <curitem> also possibly having spaces in its name.

Re: filenames with blanks in User Button script

Posted: 09 Oct 2012 02:48
by jd
Thanks for the answers!