FilesToListBox (2)




Private Sub Command1_Click()
'Clear lists

List1.Clear
List2.Clear
'Set path to starting directory

Dir1.Path = Left$(Drive1.Drive, 2) + "\"
Dir1.Refresh
File1.Path = Dir1.Path 'Set file path
File1.Refresh
'Add files in starting directory to catalog

For t& = 0 To File1.ListCount - 1
If Right$(Dir1.Path, 1) <> "\" Then 'Starting in other than root directory of drive
List2.AddItem Dir1.Path + "\" + File1.List(t&)
Else
List2.AddItem Dir1.Path + File1.List(t&) 'Starting in root directory of drive
End If
Next
'Add initial subdirectories in starting directory

For t& = 0 To Dir1.ListCount - 1
List1.AddItem Dir1.List(t&)
Next
If t& = 0 Then GoTo finishedpoint 'No subdirectories, we're done.
cnt& = 0 'Start with first directory in list
startpoint:
Dir1.Path = List1.List(cnt&)
File1.Path = Dir1.Path
'Add any subdirectories found

For t& = 0 To Dir1.ListCount - 1
List1.AddItem Dir1.List(t&)
Next
'Now add files found...

For t& = 0 To File1.ListCount - 1
List2.AddItem Dir1.Path + "\" + File1.List(t&)
Next
'Increment count

cnt& = cnt& + 1
If cnt& < List1.ListCount Then GoTo startpoint
finishedpoint:
Label1.Caption = "Total:" + Str$(List2.ListCount)
End Sub

Private Sub Form_Load()
End Sub











( filestolistbox2.html )- by Paolo Puglisi - Modifica del 17/12/2023