Function DirDiver (NewPath As String, DirCount As Integer, BackUp As String) As Integer ' Recursively search directories from NewPath down... ' NewPath is searched on this recursion. ' BackUp is origin of this recursion. ' DirCount is number of subdirectories in this directory. Static FirstErr As Integer Dim DirsToPeek As Integer, AbandonSearch As Integer, ind As Integer Dim OldPath As String, ThePath As String, entry As String Dim retval As Integer SearchFlag = True ' Set flag so user can interrupt. DirDiver = False ' Set to TRUE if there is an error. retval = DoEvents() ' check for events (i.e. user Cancels). If SearchFlag = False Then DirDiver = True Exit Function End If On Local Error GoTo DirDriverHandler DirsToPeek = dirList.ListCount ' How many directories below this? Do While DirsToPeek > 0 And SearchFlag = True OldPath = dirList.Path ' Save old path for next recursion. dirList.Path = NewPath If dirList.ListCount > 0 Then ' Get to the node bottom. dirList.Path = dirList.List(DirsToPeek - 1) AbandonSearch = DirDiver((dirList.Path), DirCount%, OldPath) End If ' Go up 1 level in directories. DirsToPeek = DirsToPeek - 1 If AbandonSearch = True Then Exit Function Loop ' Call function to enumerate files. If filList.ListCount Then If Len(dirList.Path) <= 3 Then ThePath = dirList.Path ' If at root level, leave as is... Else ThePath = dirList.Path + "\" ' otherwise put "\" before file name. End If For ind = 0 To filList.ListCount - 1 ' Add conforming files in entry = ThePath + filList.List(ind) ' this directory to listbox. lstFoundFiles.AddItem entry lblCount.Caption = Str$(Val(lblCount.Caption) + 1) Next ind End If If BackUp <> "" Then ' If there is a superior dirList.Path = BackUp ' directory, move to it. End If Exit Function DirDriverHandler: If Err = 7 Then ' If Out of Memory, assume listbox just got full. DirDiver = True ' Create Msg$ and set return value AbandonSearch. MsgBox "You've filled the listbox. Search being abandoned..." Exit Function ' Note that EXIT procedure resets ERR to 0. Else ' Otherwise display error message and quit. MsgBox Error End End If End Function