Ok... I need to put a directory with all of its subdirectories and files of a specified type into a TreeView control. Right now I'm adding the Favorites to it, and I'm running into a problem that I'm going to have to limit the amount of subdirectories I can show... How can I do this without limiting the sub directories? Here is my current code which only does all directories under the favorites, and all directories under those directories... yes, its confusing and thats why I'm going insane... here's the code I have:

(Controls:)
Treeview:tFavorites
DirectoryList:dFavorites
FileList:Urls
Note: the FavoritesPath variable is the path of the current users favorites...

Here's the code!:
Code:
Private Sub SetupFavorites()
    Dim DirsUnderFavorites As Integer
    Dim FavoritesPathLength As Integer
    Dim DirectoryLength As Integer
    Dim DirectoryName As String
    Dim FLoop As Integer
    
    dFavorites.Path = FavoritesPath
    Urls.Path = FavoritesPath
    
    DirsUnderFavorites = dFavorites.ListCount - 1
    FavoritesPathLength = Len(FavoritesPath)
    
    dFavorites.ListIndex = 0
    
    FLoop = 0
    
    Do Until FLoop = dFavorites.ListCount
    With dFavorites
        b = Len(.List(.ListIndex))
        DirectoryLength = b - FavoritesPathLength
        DirectoryName = Right(.List(.ListIndex), DirectoryLength)
        tFavorites.Nodes.Add , , FavoritesPath & DirectoryName & ":Folder", DirectoryName, 1, 2
        If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
    End With
    FLoop = FLoop + 1
    Loop
        
    Urls.ListIndex = 0
    FLoop = 0
    
    Do Until FLoop = Urls.ListCount
    With Urls
        urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
        tFavorites.Nodes.Add , , , urlstring, 3
        If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
    End With
    FLoop = FLoop + 1
    Loop
            
    dFavorites.Path = FavoritesPath
    MaxDirs = dFavorites.ListCount
    
    bfloop = 0
    dFavorites.ListIndex = 0
    Do Until bfloop = MaxDirs 'by the way, the bfloop stands for big f--king loop ^_^, floop is favorites loop
        With dFavorites
            .Path = FavoritesPath
            .ListIndex = bfloop
            .Path = .List(.ListIndex) 'dfavorites now shows all directories under the first directory under favorites
            Urls.Path = .Path 'shows all urls in current favorites path
            firstloop = True
            looped = False
            Do Until .ListIndex = .ListCount - 1
                looped = True
                'get rid of path for parent directory
                b2 = Len(.List(-1))
                DirectoryLength2 = b2 - FavoritesPathLength
                directoryname2 = Right(.List(-1), DirectoryLength2)
                
                If Urls.ListIndex + 1 < Urls.ListCount Then Urls.ListIndex = 0
                                
                .ListIndex = .ListIndex + 1
                'get rid of path for current directory
                b = Len(.List(.ListIndex))
                DirectoryLength = b - FavoritesPathLength - DirectoryLength2 - 1
                DirectoryName = Right(.List(.ListIndex), DirectoryLength)
                
                c = Len(.List(.ListIndex))
                DirectoryLength3 = c - FavoritesPathLength
                DirectoryName3 = Right(.List(.ListIndex), DirectoryLength3)
            
                tFavorites.Nodes.Add FavoritesPath & directoryname2 & ":Folder", tvwChild, FavoritesPath & DirectoryName3 & ":Folder", DirectoryName, 1, 2
                
                Urls.Path = .List(.ListIndex)
                
                FLoop = 0
                Do Until FLoop = Urls.ListCount
                    With Urls
                        If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
                        urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
                        tFavorites.Nodes.Add FavoritesPath & DirectoryName3 & ":Folder", tvwChild, , urlstring, 3
                    End With
                    FLoop = FLoop + 1
                Loop
                
                If firstloop = True And .ListIndex = .ListCount - 1 Then
                    FLoop = 0
                    oldpath = dFavorites.Path
                    olddex = dFavorites.ListIndex
                    dFavorites.Path = FavoritesPath
                    dFavorites.ListIndex = bfloop
                    Urls.Path = dFavorites.List(dFavorites.ListIndex)
                    Do Until FLoop = Urls.ListCount
                        With Urls
                            If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
                            urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
                            tFavorites.Nodes.Add FavoritesPath & directoryname2 & ":Folder", tvwChild, , urlstring, 3
                        End With
                        FLoop = FLoop + 1
                    Loop
                    firstloop = False
                    dFavorites.Path = oldpath
                    dFavorites.ListIndex = olddex
                End If
            Loop
            If looped = False Then
                FLoop = 0
                Urls.Path = dFavorites.List(dFavorites.ListIndex)
                Do Until FLoop = Urls.ListCount
                    With Urls
                        If .ListIndex < .ListCount - 1 Then .ListIndex = .ListIndex + 1
                        urlstring = Left(.List(.ListIndex), Len(.List(.ListIndex)) - 4)
                        tFavorites.Nodes.Add Urls.Path & ":Folder", tvwChild, , urlstring, 3
                    End With
                    FLoop = FLoop + 1
                Loop
            End If
        bfloop = bfloop + 1
    End With
    Loop
End Sub
Ok. I hope someone can help me out... (I'm suprised no one else ran into this problem yet!)...

-Xero