# Unable to debug this code

**URL:** <https://forum.xojo.com/t/unable-to-debug-this-code/88440>\
**Category:** macOS\
**Created:** [June 17, 2026, 12:33pm UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440 "2026-06-17T12:33:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [June 17, 2026, 12:33pm UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/1 "2026-06-17T12:33:06Z")

</div>

Worst: it display folders that ends with " - Data" on their names !

Back home because I cannot go ahead / must do somthing else.

TIA for your inputs.

```auto
Me.Icon = Create_a_ToC_Selected
Me.Refresh

Var f As FolderItem = FolderItem.ShowSelectFolderDialog()

If f Is Nil Then
  Return
End If

For Each file As FolderItem In f.Children
  
  If file = Nil Then
    // Cancel ?
    System.DebugLog "Did you pressed the Cancel button ?"
    Return
  End If
  
  If Not file.IsFolder Then
    // Not a Folder ? Exclude it
    System.DebugLog "This file name is been excluded: " + file.Name
    
  ElseIf f.Name.EndsWith(" - Data") Then
    // An object whose name ends with " - Data" ?
    // Ignore these objects
    System.DebugLog "This file name ends with “ - Data” is been excluded: " + file.Name
    
  Else
    // Display the Folder Name
    LB.AddRow(file.Name.Split(" - "))
  End If
  
  // To avoid Infinite loop
  If UserCancelled Then Exit
Next

// Revert to normal
Me.Icon = Create_a_ToC

```

The idea is to create a list of Folder Names included in the selected Folder.

Current macOS / Xojo.

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [June 17, 2026, 1:12pm UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/2 "2026-06-17T13:12:22Z")

</div>

> [@Emile\_Schwarz](#):
>
> Worst: it display folders that ends with " - Data" on their names !

Not sure what you mean: Are you concerned about folders whose name ends with “ - Data” (so you need to actively exclude these), or is it that your f.Name.EndsWith(" - Data") test doesn’t catch these folders (possibly because it’s not a minus sign but a hyphen)?

And why are you concerned about infinite loops? It’s not like a folder could contain an infinite number of children. And is it really possible for f.Children to contain a nil FolderItem? I don’t think I’ve ever cared about testing for this possibility but maybe I’m not paranoid enough. To me a test file.Exists would make more sense as the folder could in principle have been deleted after the f.Children call.

You may want to exclude invisible folders btw. but this would depend on the precise task.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [June 18, 2026, 11:47am UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/3 "2026-06-18T11:47:17Z")

</div>

Yes, I wanted to exclude any folder ending with " - Data".

unfortunately, sometimes I either do not look at the correct line(s) OR was OOM and unable to discover the error (OOM: Out of My Mind).

When I looked later, I realized why I could not exclude any Folder who Ends with " - Data":  
The code does not works because I took the wrong FolderItem to make the test !

When I replaced f with file, that part worked as expected !

Conclusion: always use meaningful variables names !

> [@Emile\_Schwarz](#):
>
> `If Not file.IsFolder Then`

The above line exclude files, incli-uding invisibles.

Testing UserCancelled is a simple caution line (just in case something wrong occured).

**AT LAST** : even if moving the code at debug time (arrow keys or MouseWheel), I discovers that the vertical bar is selectable (moveable) with the Mouse !

---

<div class="post-metadata">

**Author:** ![Graham\_Busch](https://forum.xojo.com/user_avatar/forum.xojo.com/graham_busch/32/21827_2.png) [@Graham\_Busch](https://forum.xojo.com/u/Graham_Busch)\
**Post date:** [June 18, 2026, 11:27pm UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/4 "2026-06-18T23:27:57Z")

</div>

> [@Emile\_Schwarz](#):
>
> `f.Name.EndsWith(" - Data")`

F is the parent folder. You want to check against file

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [June 19, 2026, 7:09am UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/5 "2026-06-19T07:09:59Z")

</div>

Yes, that’s it. After many hours not looking at that code, when I came back to it, I SAW where the problem lie.

That also proves I have memory troubles.

Also, using two monitors with my laptop greatly help (but this cannot amways be done). THere are so many trouble makers (high temperature, human environment, health, age, etc.).

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [June 19, 2026, 11:07am UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/6 "2026-06-19T11:07:38Z")

</div>

Buy a rubber duck. When you have a problem like this one carefully explain to the rubber duck each line in the code and suddenly you will spot the problem. Funnily enough it even works for virtual rubber ducks.

A break from the machine is also worth while, as you discovered.

> **[Rubber duck debugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging)**
>
> Rubber duck debugging (or rubberducking) is a debugging technique in software engineering, wherein a programmer explains their code, step by step, in natural language—either aloud or in writing—to reveal mistakes and misunderstandings.
> The name is a reference to an anecdote told in The Pragmatic Programmer by Andy Hunt and Dave Thomas. The book described rubber ducking as the method of explaining a problem to another party who do not "need to say a word; the simple act of explaining, step by s...

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [June 19, 2026, 2:15pm UTC](https://forum.xojo.com/t/unable-to-debug-this-code/88440/7 "2026-06-19T14:15:18Z")

</div>

What also works, sometimes, is to write a question (here) until you nearly says all…

Sometimes this allows to found the solution / sometimes (worst), you gave the solution, but for unknown reason, you cannot see it (this happened to me last month or so): i gave the answer at the end of the question ! ☹
