by Jeff Leonard (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 7th June 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Parse a directory and all sub-directories for files. Very simple. Use freely and enjoy.
File1.Pattern = "*.txt" 'Optional file pattern to match
Screen.MousePointer = 11 'Show hour glass
Parse_Subs txtOriginal.Text 'Parse directory Path.
'Could be listindex from
'another directory list box.
Screen.MousePointer = 1 'Restore mouse pointer
End Sub
Private Sub Parse_Subs(sCurrent As String)
Dim iCnt As Integer
Dim iDirCnt As Integer
Dim sSubDirs(1 To 1024) As String
Dir1.Path = sCurrent 'set Dir1 to current directory path.
File1.Path = Dir1.Path 'Fill File1 with current directory files.
If File1.ListCount > 0 Then 'Parse File1 if not empty.
For iCnt = 0 To File1.ListCount - 1
lstFiles.AddItem File1.Path & "\" & File1.List(iCnt) 'Add files to list if they match filter.
Next iCnt
End If
iDirCnt = 0
If Dir1.ListCount > 0 Then 'Parse subs if not empty.
For iCnt = 0 To Dir1.ListCount - 1
sSubDirs(iCnt + 1) = Dir1.List(iCnt) 'Fill string array with list of subs.
iDirCnt = iDirCnt + 1 'Keep track of size of string array.
Next iCnt
End If
If iDirCnt > 0 Then 'Parse string array if not empty.
For iCnt = 1 To iDirCnt
Parse_Subs sSubDirs(iCnt) 'Go down one level and start parsing there.
Next iCnt
End If
End Sub
No comments have been posted about Parse a directory and all sub-directories for files. Very simple. Use freely and enjoy.. Why not be the first to post a comment about Parse a directory and all sub-directories for files. Very simple. Use freely and enjoy..