by Loc Nguyen (5 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)
Does anything you want to files in a directory and its subdirectories. For example, if you would like to add MP3's in a directory to a playlist in your MP3 player program, this would be handy for adding all of the files including those residing in subdirectories of that directory.
'Create a DirListBox named "Dir1" and a FileListBox named "File1" and set their Visible properties to False
'Call:
' DoDirs "C:\MyDir", "*.mp3"
Public Sub DoDirs(DirPath As String, DirFilters As String)
File1.Pattern = DirFilters
Dir1.Path = DirPath
DoFiles DirPath
If Dir1.ListCount = 0 Then Exit Sub
For k = 0 To Dir1.ListCount - 1
Dir1.Path = DirPath
DoDirs Dir1.List(k), DirFilters
'DoEvents
Next k
Dir1.Path = DirPath
End Sub
Private Sub DoFiles(DirPath As String)
File1.Path = DirPath
If File1.ListCount = 0 Then Exit Sub
For k = 0 To File1.ListCount - 1
FileName = File1.Path & String(1 - Abs(CInt(Right(File1.Path, 1) = "\")), "\") & File1.List(k)
'Place what you would like to do to the files here
Next k
End Sub