filenames with blanks in User Button script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
jd
Posts: 16
Joined: 24 Dec 2007 04:26

filenames with blanks in User Button script

Post 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

highend
Posts: 14578
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: filenames with blanks in User Button script

Post by highend »

Code: Select all

run """c:\path\to\MyEditor.exe"" ""<curitem>"""; 
One of my scripts helped you out? Please donate via Paypal

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: filenames with blanks in User Button script

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

jd
Posts: 16
Joined: 24 Dec 2007 04:26

Re: filenames with blanks in User Button script

Post by jd »

Thanks for the answers!

Post Reply