FolderItem constructor problem

I have the following code in the DoubleClick event of a listbox.

var theItem as FolderItem
theItem = new FolderItem(me.SelectedRowValue, FolderItem.PathModes.Native)
theItem.parent.Open

The string in me.SelectedRowValue is a path to a file. The path is a correct native path.
When I run the code, however, the constructed FolderItem theItem is created with a path that appears to be relative to the application. In other words the path of the created folderItem is the path to the application, plus a space, plus the native path to the file.

Like this:
/Users/JohnDoe/Documents/Tools/Xojo Projects/ /Users/JohnDoe/Documents/Tools/DATA_SETS/Files/test-file.jpg

Why might that be? I’ve done this before but I’ve never seen this behavior.
What am I overlooking?

Thanks

Looking at that path there, there is a space in it.

Maybe calling trim( me.selectedRowValue ) or me.cell( me.listindex, 0 ) to get the value?

Yes, there’s a space in it – and that’s part of the issue and I’m not sure why.
The space is between what appears to be the path to the location of the application and the path to the file in question.

What OS version and version of Xojo? I did a quick test and don’t see this happen.

Latest version of Catalina; latest version of Xojo.

In the listbox, is there a space in the path or only when creating the folderitem?

I just tried with the latest Catalina and Xojo and can’t duplicate it. Just to confirm, if you stick a “MessageBox me.selectedRowValue” before you create theItem, you get " “/Users/JohnDoe/Documents/Tools/DATA_SETS/Files/test-file.jpg” and if you do “MessageBox theItem.NativePath” afterward, you get the version with the space?

Are you saying that Xojo is adding a space to the left of the path?

Seems really odd… And I would recommend that someone who can reproduce this file a Feedback Report with Xojo ASAP.

In the meantime if you use trim( <path/> ) does this resolve it?

Edit: Trimming the path may resolve this problem, but it will break the ability for a user to select a file with has a space at the end of the file name. Perhaps using

if left( path, 1 ) = " " then
  path = right( path, len( path ) -1 )
end if

(off) - I find using the rowtag to hold a folderitem reference is easier
As you build your listbox, instead of just doing the name as the text of the row, set the rowtag to be the folderitem

Then, your code becomes something like this (I dont use API2 myself)

var theItem as FolderItem
theItem = me.rowtag(row)
theItem.parent.Open

That’s handy to know for other things I’m doing but in this case I’m getting the path by parsing the string output of a third party terminal routine. (My problem was that I failed to notice a space at the beginning of the parsed string. Fixed with a String.TrimLeft.)

@samRowlands that was it. The path is the result of parsing the string outpout of a third party terminal routine. I failed to notice a space at the beginning of the parsed string. Fixed with a String.TrimLeft .

Thanks

1 Like

Awesome. Glad we figured it out, because it was weird when I was thinking it might be folderitem giving a duff path.

Not wanting to derail this thread, but this is sort-of on topic.

I’ve had issues storing the folderitem in the rowtag on Mac. The file couldn’t be found when retrieving the folderitem from the listbox. Had to change to storing the nativepath instead.

This was with API2, but supposedly the underlying functions shouldn’t have changed. I haven’t taken the time to test it under API1 to see if it performs differently.

API 2 has had weird bugs
A RecordSet in API 1 works but the rowset didnt and switching back worked again
There have been several cases reported like that where updating to the API 2 version didnt work as expected
This could be another case like that

Its not confidence inspiring

1 Like

I have often stashed API 1 FolderItems in RowTags without issue. I don’t do API 2, but this certainly gives me pause…

2 Likes

Y’know, “I don’t do API 2” would make a great T-shirt…

1 Like

API 2
Just Say No !

1 Like

Yes, but mine rhymes :stuck_out_tongue_closed_eyes:

Mebbe:

API 2
Just Say Eww :nauseated_face:

As long as the emoji can be put on the shirt as well !

Such a reason why I hate when the Shell is the only way to do something, as parsing shell results are hard and easily unreliable.
I won’t ever understand why Shell and terminal commands can be “preferred methods” for some.