Function to return an array of filenames from a passed directory:   Return to List

Public Function aryFilesInDir(ByVal strPath As String) As Variant
' ----------------------------------------------------------------------
' Function to return an array of filenames from a passed directory
'      array is 1 based
' ----------------------------------------------------------------------
' declare locals
Dim aryFiles() As String
Dim sfile As String
Dim intCount As Integer
intCount = 0
' prep pattern from passed path
strPathPattern = strPath & "\*.*"
' run the dir cmd using the pattern
sfile = Dir(strPathPattern)
If Len(sfile) > 0 Then
    ' note the initial file returned
    If sfile <> "." And sfile <> ". ." Then
        intCount = intCount + 1
        ReDim aryFiles(intCount)
        aryFiles(intCount) = sfile
    End If
    ' Do the remaining files
    Do While sfile <> ""
        sfile = Dir()
        If sfile <> "." And sfile <> ". ." Then
            intCount = intCount + 1
            ReDim Preserve aryFiles(intCount)
            aryFiles(intCount) = sfile
        End If
    Loop
End If
aryFilesInDir = aryFiles()
End Function



Note to Webmaster