Directory list and treeview

BlitzMax Forums/BlitzMax GUI Programming/Directory list and treeview

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Try this:
Strict 

Global window:TGadget=CreateWindow("My Window",50,50,240,240)
Global treeview:TGadget=CreateTreeView(0,0,200,200,window)
SetGadgetLayout treeview,2,2,2,2

Global root:TGadget=TreeViewRoot(treeview)

Global Drive:String="C:"
Global Direc:String="library"

Global directory:TGadget
directory=AddTreeViewNode(Drive,root)
directory=AddTreeViewNode(Direc,directory)

Global Previous:TGadget

ListFiles(directory, Drive+Direc)

While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
	Case EVENT_WINDOWCLOSE
		End
	End Select
Wend

Function ListFiles( folder:TGadget, rootdir:String)
	Local dir:Int = ReadDir( rootdir)
	Local subfolder:TGadget
	If Not dir Then Return
	
	'If Not rootdir.EndsWith("/") Then rootdir:+ "/"
	Repeat
		Local fn:String = NextFile(dir)
		If Not fn Then Exit ' <-- this is important, we dont want an endless loop
		
		If FileType( rootdir+"/"+fn) = 2 And fn<>"." And fn<>".." Then
			subFolder = AddTreeViewNode( fn, folder )			
			ListFiles( subFolder, rootdir+"/"+fn) ' <-- recurse over this folder
		EndIf
	Forever
	CloseDir dir
EndFunction