B4J Question Tree list for Directory with checkbox and more than 1 levels

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All

I want to have a dialog box that allows me to choose Directories / subdirectories and once tagged then make a sql file of the full path of each file in those directories / sub directories / Sub / Sub / Sub ect

I can recursivley get all the file names from a directory but sometimes do not want all of the sub directories of that directory.

I hope this is makes sense.


I have been trying all different methods for a while and taking code from all over this forum to try and make this work.

I want to firstly choose what Drive I want to scan but I have not seen anything that might help, so I have come to the conclusion to put a field in the Settings of the program.

The problem is really the extra levels. I can get the Root and one level working ok except it does show the directory name in the 1st level of the level I have entered. If I do not put something there then the tree option in TreeView does not appear.

One way to solve this is maybe to ready the complete drive and build all the directory tree before displaying anything. At the moment we are only reading the next level directory tree when we open it in TreeView.


If I could determine which level I was on I could then change this to get a directory of the next level
B4X:
FolderList("i:\" & ti.Text)




B4X:
    #MainFormWidth: 800
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private TreeView1 As TreeView
    Dim folders As List
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("dirtree") 'Load the layout file.
    MainForm.Show
    TreeView1.SetCheckBoxesMode
   
    FolderList("i:\")
    For i = 0 To folders.Size-1
        Dim ti As CheckboxTreeItem
             ti.Initialize("ti", folders.Get(i))
        Dim cti As CheckboxTreeItem
             cti.Initialize("cti", folders.Get(i))
        Dim ctp As CheckboxTreeItem
                ctp.Initialize("cti", folders.Get(i))
        cti.Children.Add(ctp) 'add the child of the child
                   ti.Children.Add(cti) 'add the child
                 TreeView1.Root.Children.Add(ti)
    Next
     End Sub
    
    Sub FolderList(folder As String) As List
   
   folders.Initialize
   folders.Clear
   For Each f As String In File.ListFiles(folder)
     If File.IsDirectory(folder, f) = True Then
         folders.Add(f)
     Dim a As String = f
     Log(a)
     Else
   End If
   Next
  
   Return folders
  
End Sub

Sub TI_ExpandedChanged(Expanded As Boolean)
    If Expanded = True Then
        Dim ti As CheckboxTreeItem = Sender

    FolderList("i:\" & ti.Text)
    Log("ti.text ="&ti.Text)
        For i = 0 To folders.Size-1
            Dim ti1 As CheckboxTreeItem

    ti1.Initialize("ti1", folders.Get(i))
        Dim cti1 As CheckboxTreeItem
   cti1.Initialize("cti1",folders.Get(i))
            Dim ctp1 As CheckboxTreeItem
    ctp1.Initialize("cti1", folders.Get(i))
                cti1.Children.Add(ctp1) 'add the child of the child
                       ti.Children.Add(cti1) 'add the child
                   TreeView1.Root.Children.Add(ti1)
      Next
     Else
                  folders.Clear
        End If

End Sub



Sub TreeView1_SelectedItemChanged(SelectedItem As TreeItem)
   
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…