open a file with spaces


i have a Exeapp which opens files such as xls, doc, jpg, ect …

how is it possible to open files with Spaces in the file name … ?

i read somewhere by surrounding the name of the file with single quotes: character 39, it should do the trick, the 39 character doesn’t seem to work

if i go to finder and double click on a file with spaces the associated editor / viewer will open the file.

this code fails with filenames with spaces. ( folders and directories also )
The editor opens with a blank document / new screen, the appArg does not load

Dim sh As New Shell sh.Execute "open -n " + AppPath.ShellPath + " --args " + Chr(39) + appArg + Chr(39)

This code will work with filenames with no spaces.

Dim sh As New Shell sh.Execute "open -n " + AppPath.ShellPath + " --args " + appArg

Here you did put the quotes around the arguments, not the filename:

And you need to put the whole path in quotes, not the filename alone:

Dim sh As New Shell sh.Execute "open -n """ + AppPath.ShellPath + """ --args " + appArg

First part (with Finder) is false.

Second part (the Terminal) example are…

You have to use two quotes if the target folder have space(s) in its name:

ls "My Folder With Spaces "

What is an Exeapp in the macOS context ?

Try using single quotes directly from your keyboard instead of chr(39). You may be getting some unintended encoding issues there.

Dim sh As New Shell sh.Execute "open -n " + AppPath.ShellPath + " --args ‘" + appArg + “‘“

Also, if AppArg is a path and you’re putting it in quotes, you should use NativePath instead of ShellPath and each argument should be enclosed in quotes, not all of them together.

I think you need to use chr(34)

Chris character 34 is " ( double quotes )

Emile ::: please see an example of ExecApp ( execute other app )

Dim editor As FolderItem editor = New FolderItem(MainWin.SpreadSheet.Text, FolderItem.PathTypeNative) MainWin.ExecApp(editor, Mainwin.LocalPathSelector.Text + "/" + File)

Greg i did use single quotes using Chr(39)…
Single Quotes from the Keyboard does not seem to work either, even if the file has no spaces.
but … Args in Native ? ok i’ll try it.

the path of the outside App to run has no problem with spaces,
it is the AppArg the argument to the outside app that is the problem if it has spaces.
The AppArg is the file for the other app ( outside app ) to open.

here is the args in nativepath, it does not seem to work either. w/ or without single quotes does not seem to work either.

  Dim p As FolderItem = New FolderItem(MainWin.LocalPathSelector.Text + "/" + File, FolderItem.PathTypeNative)
  MainWin.ExecApp(editor, p)

Dim sh As New Shell
sh.Execute “open -n " + AppPath.ShellPath + " --args '” + appArg.NativePath +"’"


Do this for us

s= "open -n " + AppPath.ShellPath + " --args '" + appArg.NativePath +"'"
msgbox s

post what that says so we can SEE the actual string

here is the exact string displayed by MSGBOX

open -n /Applications/Microsoft\\ Office\\ 2008/Microsoft\\ --args '/Volumes/Production/culser/Sites/non_adult/shop/_production/_warnings/This End Up.xls'

While technically the Shellpath part is “escaped” with the “”… I would go ahead and enclose it in " as well

and I think you need ChrB(34) (double quotes)

"open -n " + chrb(34)+ AppPath.ShellPath +chrb(34)+ " --args "+chrb(34) + appArg.NativePath +chrb(34)


putting all in Chr(34) now the outside app will not open

sh.Execute "open -n " + Chr(34)  + AppPath.ShellPath + Chr(34) + " --args " + Chr(34)  + appArg.NativePath + Chr(34)

without Chr(34) the AppPath.ShellPath did execute.
Assuming the shellpath is escaping the white spaces by \space

appArg.Nativepath does not escape out spaces.

here is an interesting development
i am using Gimp to open images
using this code
sh.Execute "open -n " + AppPath.ShellPath + " --args " + appArg.ShellPath

gimp works … spaces or no spaces in the path

I am using sublime to open text files such as txt / html / dat / ini files ect …
sublime works using the same shellpath code …

it seems only the spreadsheet app excel and word do not open files using ShellPath/ nativepath / or encasing in Chr(34)

There is another path format (URLPath?) the would insert “%20” at each space… try that instead of Nativepath…
(grasping at straws here)

Is applescript an option for you David?

If so, you can use the following to open a file in Excel, which works with or without spaces in the path:

dim sh as new Shell sh.Execute "osascript -e ""tell application \""Microsoft Excel\"" to open \""" + appArg.NativePath + "\"""""

URLPATH gives an Exception and my App Fails.

Jared apple script may be a possibility.

or just tell the specific file to open and the users preferred app to handle that kind of file will open ?



Norman so you are saying

Dim appArg As folderitem

appArg.Launch ?

as long as apparg already is a folderitem that points to the file you want to launch - yes

I dont see in your first post how you create that

Norman how about

Dim appArg As FolderItem = GetFolderItem(appArgPath.Text, FolderItem.PathTypeNative)