Jobs
Author: Jeff Leonard Date Submitted: 7/6/2007 Category: File Manipulation Compatibility: VB 6 This code has been accessed 3310 times.
Email Yourself this snippet:
No Declarations needed. My example uses a directory path from a text box. This path could also be picked using the listindex from another directory list box. Other controls used are a directory list box, a file list box, a list box and a command button. I keep the directory list box and the file list box invisible.
Code
Private Sub cmdParse_Click() 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