[FUNCTION] GetSubFolders(address, depth) As String() (1 Viewer)

BlueIshDan

☠
Local time
Today, 03:28
Joined
May 15, 2014
Messages
1,122
To see this function used to fill a table with all files in the subdirectories lower than an access database file location, follow this link:
http://www.access-programmers.co.uk/forums/showthread.php?t=264990

Code:
' Reference Microsoft Scripting Runtime
Public Function GetSubFolders(address, depth) As String()
    
    Dim fs As New FileSystemObject
    Dim sub_folders() As String
    Dim folder_count As Long
    Dim new_bundle_count As Long
    Dim temp_folder_count As Long
    
    ' Check the existance of the directory.
    If fs.FolderExists(address) Then
        
        ' Store the initial list of subfolders into an array.
        For Each var_folder In fs.GetFolder(address).SubFolders
            ReDim Preserve sub_folders(folder_count)
            sub_folders(folder_count) = var_folder
            folder_count = folder_count + 1
        Next
        
        ' With i = 1, we will look into each of the initially collected _
        ' subfolders, and collect of their sub folders.
        
        ' For each increment until we reach the requested depth, we will
        ' collect the subfolders within each of the last result of subfolders.
        
        ' For your knowledge: _
        '                    The result will return an array that seems
        '                    to be sorted by depth.
        For i = 1 To depth
            temp_folder_count = folder_count
            For j = new_bundle_count To temp_folder_count - 1
                new_bundle_count = new_bundle_count + 1
                For Each var_folder In fs.GetFolder(sub_folders(j)).SubFolders
                    ReDim Preserve sub_folders(folder_count)
                    sub_folders(folder_count) = var_folder
                    folder_count = folder_count + 1
                Next
            Next
        Next
        
    End If
    
    GetSubFolders = sub_folders
    
End Function
 

Users who are viewing this thread

Top Bottom