FolderItem.Launch

I do not know if FolderItem.Launch has ever worked in Linux when spaces in filename,
the error has now happened to me for the first time

dim f as FolderItem = GetFolderItem("/Axel_2/TestFolder/my test.txt", 3)
if f <> nil and f.Exists then
 Window1.Title = "File found"
 f.Launch
else
 Window1.Title = "File not found"
end if

Error:

[quote]Die Adresse »file:///Axel_2/TestFolder/my%5C%20test.txt« konnte nicht geöffnet werden.
Fehler beim Holen der Informationen für Datei »/Axel_2/TestFolder/my\ test.txt«: Datei oder Verzeichnis nicht gefunden.[/quote]

(can not be opened, file not found)

that confuses me, who changes the path here? Xojo or Ubuntu ?

/Axel_2/TestFolder/my test.txt -> file:///Axel_2/TestFolder/my%5C%20test.txt -> /Axel_2/TestFolder/my\ test.txt
(nativepath -> urlpath -> shellpath)

after closing error message Window1.Title is “File found”

the code works well in OSX,
and it works in Linux when there are no blank spaces in the filename.

I know I can use xgd-open, but I want to understand what’s going on

Did you try?

dim f as FolderItem = GetFolderItem("/Axel_2/TestFolder/my\\ test.txt", 3)

[quote=312121:@Björn Dohle]Did you try?

dim f as FolderItem = GetFolderItem("/Axel_2/TestFolder/my\\ test.txt", 3)

Which would then be a shellpath and should be

dim f as FolderItem = GetFolderItem("/Axel_2/TestFolder/my\\ test.txt", 1)

same error, also when I use an open dialog

dim f as FolderItem = GetOpenFolderItem("")

As I said, it works in OSX. The problem must be somewhere else (space in filename)

Looks like this has been previously reported: feedback://showreport?report_id=29275

I would strongly suggest NOT writing it as you have using an integer value since its not clear what 3 means making your code unnecessarily unclear
Instead use the defined constants that help your code be readable

dim f as FolderItem = GetFolderItem("/Axel_2/TestFolder/my test.txt", FolderItem.PathTypeNative)

I compiles in EXACTLY the same way since this is a defined constant but the code ends up being much more readable with that one tiny change

You mean in the forum?

I use this mostly, Xojo and I know what 3 means :slight_smile:

[quote=312141:@Axel Schneider]You mean in the forum?
[/quote]
Everywhere

Should any future version of Xojo alter the constants your code will break - but it wont with the constants unless we remove one
It will continue to work if you use the constant
Anyone you share code with will appreciate it (like us here in a bug report)

Its just a good practice IMHO

%5C = \
%20 = space

Does xojo internally use URLPath for files?

If so, then %5C could be the problem, only %20 is needed

Not as far as I know

and launch may be failing for reasons completely unrelated to the path
its certainly possible to get a valid folderitem that is constructed from a path with spaces in it
and launch may still fail

I’m not sure how, on linux, it figures out what app to use to “launch and open” the relevant folderitem
That may be the issue here

It affects all files, no matter what file extension.

Curiously, however, ‘launch’ works with application files that contain blank spaces
(which has no file extension)

executable files will probably work

but for NON-executable files (say a text document) it wont

You can work around that, and this should work on most distros

   if needsParams then
           // use folderitem.Launch + parameters
   else
         ShowUrl( folderitem.URLPath )
   end if

or you might test the item and see if its executable and if so use folderitem.launch otherwise use showurl

Thanks Norman,

ShowUrl (folderitem.URLPath) is the solution.

It opens the files with the default application

Just by the way,
the problem also occurs when you drag a file with space in filename into the Xojo IDE

right click in Navigator -> ‘Open File’ -> the same error message comes