How about using recursion? It's an elegant solution to solving problems that deal with trees! Grab the following class and test code. Enjoy!<br>
<br>
-----<Class Start>-----<br>
Option Explicit<br>
<br>
Private colDirs As Collection<br>
Private colFiles As Collection<br>
<br>
Private sStartDir As String<br>
Private sFileSpec As String<br>
Private bCollSet As Boolean<br>
<br>
Public Function FindFiles()<br>
<br>
Dim i, iFirst, iSecond, iDirCount As Integer<br>
<br>
If sStartDir = "" Then<br>
Err.Raise Number:=5, _<br>
Source:="FindFile.Directory", _<br>
Description:="Directory Property must be supplied."<br>
End If<br>
If sFileSpec = "" Then<br>
Err.Raise Number:=5, _<br>
Source:="FindFile.FileSpec", _<br>
Description:="File Specification Property must be supplied."<br>
End If<br>
If bCollSet = False Then<br>
Err.Raise Number:=5, _<br>
Source:="FindFile.Collection", _<br>
Description:="Collection Property must be supplied."<br>
End If<br>
<br>
RecurseDirs sStartDir, sFileSpec<br>
<br>
While colDirs.Count > 0<br>
iDirCount = colDirs.Count<br>
RecurseDirs colDirs(1), sFileSpec<br>
If colDirs.Count = iDirCount Then<br>
For i = 1 To colDirs.Count<br>
iFirst = CountChar(colDirs(1), "\"

<br>
If colDirs.Count > 1 Then<br>
iSecond = CountChar(colDirs(2), "\"

<br>
Else<br>
iSecond = False<br>
End If<br>
If iFirst > iSecond And iSecond Then<br>
colDirs.Remove 1<br>
End If<br>
Next<br>
colDirs.Remove 1<br>
End If<br>
Wend<br>
<br>
End Function<br>
<br>
Private Sub Class_Initialize()<br>
<br>
Set colDirs = New Collection<br>
Set colFiles = New Collection<br>
<br>
End Sub<br>
<br>
Private Function RecurseDirs(Path, FileSpec)<br>
<br>
Dim sFound As String<br>
Dim sCurrentPath As String<br>
<br>
If Mid$(Path, Len(Path)) <> "\" Then<br>
Path = Path & "\"<br>
End If<br>
<br>
sCurrentPath = CurDir<br>
ChDir Path<br>
<br>
sFound = Dir(Path & FileSpec, vbNormal + vbHidden + vbSystem + vbReadOnly)<br>
While sFound <> ""<br>
colFiles.Add Item:=Path & sFound<br>
sFound = Dir<br>
Wend<br>
<br>
sFound = Dir(Path & "*.*", vbDirectory + vbNormal + vbHidden + vbSystem + vbReadOnly)<br>
While sFound <> ""<br>
If (Left(sFound, 1) <> "."

And (GetAttr(Path & sFound) And vbDirectory) Then<br>
If colDirs.Count = 0 Then<br>
colDirs.Add Item:=Path & sFound<br>
Else<br>
colDirs.Add Item:=Path & sFound, Before:=1<br>
End If<br>
End If<br>
sFound = Dir<br>
Wend<br>
<br>
ChDir sCurrentPath<br>
<br>
End Function<br>
<br>
Private Function CountChar(sString As String, sChar As String) As Integer<br>
<br>
Dim iPos As Integer<br>
<br>
iPos = InStr(sString, sChar)<br>
While iPos <> 0<br>
CountChar = CountChar + 1<br>
iPos = InStr(iPos + 1, sString, sChar)<br>
Wend<br>
<br>
End Function<br>
<br>
Public Property Let Directory(sDir As String)<br>
<br>
Dim sTemp As String<br>
Dim iOptions As Integer<br>
<br>
If sDir = "" Then<br>
Err.Raise Number:=5, _<br>
Source:="FindFile.Directory", _<br>
Description:="Directory Property must be supplied."<br>
Else<br>
sStartDir = sDir<br>
End If<br>
<br>
End Property<br>
<br>
Public Property Let FileSpec(FileSpec As String)<br>
<br>
Dim iOptions As Integer<br>
<br>
If FileSpec = "" Then<br>
Err.Raise Number:=5, _<br>
Source:="FindFile.FileSpec", _<br>
Description:="File Specification Property must be supplied."<br>
Else<br>
sFileSpec = FileSpec<br>
End If<br>
<br>
End Property<br>
<br>
Public Property Set Collection(vObject As Object)<br>
<br>
Set colFiles = vObject<br>
bCollSet = True<br>
<br>
End Property<br>
<br>
Private Sub Class_Terminate()<br>
Set colDirs = Nothing<br>
Set colFiles = Nothing<br>
End Sub<br>
-----<Class End>-----<br>
<br>
-----<Test Program Start>-----<br>
Option Explicit<br>
<br>
Public Sub Main()<br>
Dim objFile As FileFind<br>
Dim colFiles As Collection<br>
Dim lIndex As Long<br>
<br>
'Create the FileFind Object.<br>
Set objFile = New FileFind<br>
<br>
'Create a collection to hold the list of files it found.<br>
Set colFiles = New Collection<br>
<br>
'Tell it the directory to search.<br>
objFile.Directory = "C:\TEMP"<br>
<br>
'Tell it what to search for.<br>
objFile.FileSpec = "*.exe"<br>
<br>
'Tell it where to put the files that were found.<br>
Set objFile.Collection = colFiles<br>
<br>
'Tell it to get to work!<br>
objFile.FindFiles<br>
<br>
'Display the files it found.<br>
For lIndex = 1 To colFiles.Count<br>
Debug.Print colFiles(lIndex)<br>
Next lIndex<br>
End Sub<br>
-----<Test Program End>-----<br>
<br>
<p>Steve Meier<br><a href=mailto:sdmeier@jcn1.com>sdmeier@jcn1.com</a><br><a href= > </a><br>