I'm having a major mental block at the moment and can't figure this basic thing out. All I want to do, is populate a TreeGadget with a recursive folder listing, as shown below. Left is the folder structure, and right is what I want to achieve. It should work with multiple sub-folders, too. I don't know what the heck I'm doing wrong but I can't do it. And yes, it has to be a TreeGadget only (not any other gadget type). Can someone please post some bleeding obvious code for me? Thanks.
Note: I've already got the recursed file list saved in an array; I just can't seem to make each new parent folder (and its sub-folders) be a new "node" with indented kids, especially with folder 3 and it's sub-folders.

Code: Select all
Dim f$(9)
f$(1)="Folder 1\File 11"
f$(2)="Folder 1\File 12"
f$(3)="Folder 1\File 13"
f$(4)="Folder 2\File 21"
f$(5)="Folder 2\File 22"
f$(6)="Folder 2\File 23"
f$(7)="Folder 3\Sub-folder 3\File 331"
f$(8)="Folder 3\Sub-folder 3\File 332"
f$(9)="Folder 3\Sub-folder 3\File 333"
If OpenWindow(0, 0, 0, 355, 200, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, 340, 180) ; TreeGadget standard
For i=1 To 9
f$=f$(i)
s=FindString(f$,"\")
dir$=Left(f$,s-1)
If dir$<>""
f$=Mid(f$,Len(dir$)+2)
If dir$<>old$
old$=dir$
AddGadgetItem(0,-1,dir$,0,0)
AddGadgetItem(0,-1,f$,0,1)
Else
AddGadgetItem(0,-1,f$,0,1)
EndIf
EndIf
Next
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf