Load Folder content into ListBox

I want to load an entire folder, and subfolders, contents into a hierarchical listbox. I already have an array of all the paths so don’t need to go back to the disk for the information.

The array looks like this:
/folder/subfolder/file.1
/folder/subfolder/file.2
/folder/subfolder/childfolder/file.3
/folder/subfolder/childfolder/subchildfolder/file.4

etc.

I can’t work out a recursive function to populate a hierarchical listbox, has anyone done it? I’ve searched the forum and there are a few posts on similar topics, but nothing that quite fits my requirements.

I know it’s a For Each loop, but can’t get my head around the logic!

Have-you checked the examples ? I think there is one that do that to the Desktop folder.

1 Like

I have. There are 2 file browser examples. “File Browser” doesn’t work, and “FileBrowser” works sort of, but is buggy and way over the top compared to what i am trying to achieve.

(and i’ll file a bug report when I get a moment)

1 Like

Sorry.

I’m on Windows 11 and XOJO 2025r1.1. I only see one File Browser example “Xojo Examples\Files\File Browser.xojo_binary_project” and it works fine for me. If your having trouble with a treeview you could always look at the Einhugur Software plugin TreeView. I have not used it much more than to play with it’s examples.

It’s quite clever to have 2 examples with almost the same name. And the less said about the code quality of the examples the better.

The data structure of the examples doesn’t fit.

I have some really old code to handle this - I think the code is from the original Realbasic book. I’ll make an example.

1 Like

This is quickly slapped together from the old code (2001!!!):

hierarchicalListBox.xojo_xml_project.zip (7.0 KB)

I use this to show mailboxes. Some users have a lot of mailboxes but I haven’t tested this on 100k:

1 Like

thank you! i’ll test this out today :slight_smile:

thank you, this is great.

on a related topic, am I right in saying that child items of a listbox hierarchy do not exist until the row is expanded? If so, what is the rationale for this? I assume it is memory and UI performance, but this seems a little weak for a reason overall versus having to build and process each time a row is expanded.

I come from a .NET world originally, and the TreeView control doesn’t have this design choice. You essentially build the entire tree in one go.

Yes.

You populate the “Expand stuff” in a dedicated Event ( RowExpanded(Row As Integer)).

1 Like

I really haven’t a clue. It’s one of those things “it’s been like that forever”. The non-hierarchical listbox gets a bit slower when you load a lot of data.