I am using code to identify folders and their documents. This code works on a crude form of splitting/listing folders and documents, but how can I split subdirectories and their documents in another group? Thanks
Private Sub Command0_Click()
Dim fso As Object
Dim fld As Object
Dim sfl As Object
Dim fil As Object
Dim gg As Integer
gg = 1
Me.List1.RowSource = "": Me.List1b.RowSource = ""
Me.List2.RowSource = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder("K:\Documents1")
' Loop through the folders
For Each sfl In fld.SubFolders
Me.List1.AddItem sfl.Name & " " & gg
' Loop through the files in the subfolder
For Each fil In sfl.Files
Me.List2.AddItem fil.Name & " " & gg
Next fil
gg = gg + 1
Next sfl
End Sub
Private Sub Command0_Click()
Dim fso As Object
Dim fld As Object
Dim sfl As Object
Dim fil As Object
Dim gg As Integer
gg = 1
Me.List1.RowSource = "": Me.List1b.RowSource = ""
Me.List2.RowSource = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder("K:\Documents1")
' Loop through the folders
For Each sfl In fld.SubFolders
Me.List1.AddItem sfl.Name & " " & gg
' Loop through the files in the subfolder
For Each fil In sfl.Files
Me.List2.AddItem fil.Name & " " & gg
Next fil
gg = gg + 1
Next sfl
End Sub