# FolderItem constructor problem

**URL:** <https://ifnotnil.com/t/folderitem-constructor-problem/1327>\
**Category:** macOS\
**Created:** [14 November 2020 23:40 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327 "2020-11-14T23:40:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![psb87](https://ifnotnil.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@psb87](https://ifnotnil.com/u/psb87)\
**Post date:** [14 November 2020 23:40 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/1 "2020-11-14T23:40:44Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![samRowlands](https://ifnotnil.com/user_avatar/ifnotnil.com/samrowlands/32/121_2.png) [@samRowlands](https://ifnotnil.com/u/samRowlands)\
**Post date:** [15 November 2020 00:16 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/2 "2020-11-15T00:16:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![psb87](https://ifnotnil.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@psb87](https://ifnotnil.com/u/psb87)\
**Post date:** [15 November 2020 00:31 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/3 "2020-11-15T00:31:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BillG](https://ifnotnil.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@BillG](https://ifnotnil.com/u/BillG)\
**Post date:** [15 November 2020 00:36 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/4 "2020-11-15T00:36:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![psb87](https://ifnotnil.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@psb87](https://ifnotnil.com/u/psb87)\
**Post date:** [15 November 2020 00:54 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/5 "2020-11-15T00:54:41Z")

</div>

Latest version of Catalina; latest version of Xojo.

---

<div class="post-metadata">

**Author:** ![samRowlands](https://ifnotnil.com/user_avatar/ifnotnil.com/samrowlands/32/121_2.png) [@samRowlands](https://ifnotnil.com/u/samRowlands)\
**Post date:** [15 November 2020 01:42 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/6 "2020-11-15T01:42:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BillG](https://ifnotnil.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@BillG](https://ifnotnil.com/u/BillG)\
**Post date:** [15 November 2020 02:26 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/7 "2020-11-15T02:26:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![samRowlands](https://ifnotnil.com/user_avatar/ifnotnil.com/samrowlands/32/121_2.png) [@samRowlands](https://ifnotnil.com/u/samRowlands)\
**Post date:** [15 November 2020 02:53 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/8 "2020-11-15T02:53:55Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![JeffT](https://ifnotnil.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@JeffT](https://ifnotnil.com/u/JeffT)\
**Post date:** [15 November 2020 07:06 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/9 "2020-11-15T07:06:47Z")

</div>

(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
```

---

<div class="post-metadata">

**Author:** ![psb87](https://ifnotnil.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@psb87](https://ifnotnil.com/u/psb87)\
**Post date:** [15 November 2020 14:53 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/10 "2020-11-15T14:53:20Z")

</div>

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`.)

---

<div class="post-metadata">

**Author:** ![psb87](https://ifnotnil.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@psb87](https://ifnotnil.com/u/psb87)\
**Post date:** [15 November 2020 14:55 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/11 "2020-11-15T14:55:49Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![samRowlands](https://ifnotnil.com/user_avatar/ifnotnil.com/samrowlands/32/121_2.png) [@samRowlands](https://ifnotnil.com/u/samRowlands)\
**Post date:** [16 November 2020 01:41 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/12 "2020-11-16T01:41:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jmadren](https://ifnotnil.com/user_avatar/ifnotnil.com/jmadren/32/65_2.png) [@jmadren](https://ifnotnil.com/u/jmadren)\
**Post date:** [16 November 2020 15:30 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/13 "2020-11-16T15:30:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [16 November 2020 16:58 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/14 "2020-11-16T16:58:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prodman](https://ifnotnil.com/user_avatar/ifnotnil.com/prodman/32/81_2.png) [@prodman](https://ifnotnil.com/u/prodman)\
**Post date:** [16 November 2020 17:17 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/15 "2020-11-16T17:17:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prodman](https://ifnotnil.com/user_avatar/ifnotnil.com/prodman/32/81_2.png) [@prodman](https://ifnotnil.com/u/prodman)\
**Post date:** [16 November 2020 17:18 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/16 "2020-11-16T17:18:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [16 November 2020 19:55 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/17 "2020-11-16T19:55:19Z")

</div>

API 2  
Just Say No !

---

<div class="post-metadata">

**Author:** ![prodman](https://ifnotnil.com/user_avatar/ifnotnil.com/prodman/32/81_2.png) [@prodman](https://ifnotnil.com/u/prodman)\
**Post date:** [16 November 2020 20:10 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/18 "2020-11-16T20:10:24Z")

</div>

Yes, but mine rhymes 😝

Mebbe:

API 2  
Just Say Eww 🤢

---

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [16 November 2020 21:20 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/19 "2020-11-16T21:20:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anic297](https://ifnotnil.com/user_avatar/ifnotnil.com/anic297/32/18_2.png) [@anic297](https://ifnotnil.com/u/anic297)\
**Post date:** [20 November 2020 11:09 UTC](https://ifnotnil.com/t/folderitem-constructor-problem/1327/20 "2020-11-20T11:09:29Z")

</div>

> [@psb87](#):
>
> @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` .

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.
