FilesIn_Array and FoldersIn_Array

Return list of files in a folder back as array.
Similar to FilesIn, but this one returns in array rather than in string
Also, we have FoldersIn_Array to return folders back as array, just like FoldersIn.


Code was modified after generated by Bing AI

CodeFunctionName
What is this?

Public

Tested

Original Work
Function FilesIn_Array(folderPath)
    Dim fso As Object
    Dim sourceFolder As Object
    Dim file As Object
    Dim filePaths() As String
    Dim i As Integer
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set sourceFolder = fso.GetFolder(folderPath)
    ' Set the size of the array based on the number of files in the folder
    ReDim filePaths(sourceFolder.Files.Count - 1)
    i = 0
    ' Retrieve the file paths in the folder
    For Each file In sourceFolder.Files
        filePaths(i) = file.Path
        i = i + 1
    Next file
    FilesIn_Array = filePaths
End Function

Function FoldersIn_Array(folderPath)
    Dim fso As Object
    Dim sourceFolder As Object
    Dim file As Object
    Dim filePaths() As String
    Dim i As Integer
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set sourceFolder = fso.GetFolder(folderPath)
    ' Set the size of the array based on the number of files in the folder
    ReDim filePaths(sourceFolder.subFolders.Count - 1)
    i = 0
    ' Retrieve the file paths in the folder
    For Each file In sourceFolder.subFolders
        filePaths(i) = file.Path
        i = i + 1
    Next file
    FoldersIn_Array = filePaths
End Function

folderPath

Views 134

Downloads 81

CodeID
DB ID