EnumFiles




Function ListSubDirs(ByVal Path As String) As Variant
'returns an array of directory names

On Error Resume Next
Dim Count, Dirs(), i, DirName ' Declare variables.
DirName = Dir(Path, vbDirectory) ' Get first directory name.
Count = 0

Do While Not DirName = ""
'A file or directory name was returned

If Not DirName = "." And Not DirName = ".." Then
'Not a parent or current directory entry so process it

If GetAttr(Path & DirName) And vbDirectory Then
'This is a directory Increase the size of the

'array by one element

ReDim Preserve Dirs(Count + 1)
Dirs(Count) = DirName ' Add directory name to array
Count = Count + 1 ' Increment counter.
End If
End If
DirName = Dir ' Get another directory name.
Loop
ReDim Preserve Dirs(Count - 1) 'remove the last empty element
ListSubDirs = Dirs()
End Function


Function ListFiles(ByVal Path As String) As Variant
'returns an array of file names

On Error Resume Next
Dim Count, Files(), i, FileName ' Declare variables.
Count = 0
FileName = Dir(Path, 6) ' Get first file name.


Do While Not FileName = ""


If Not FileName = "." And Not FileName = ".." Then
'Not a parent or current directory entry

' so process it



If Not GetAttr(Path & FileName) And vbDirectory Then
'This is a file

'Increase the size of the array by one e

' lement

ReDim Preserve Files(Count + 1)
Files(Count) = FileName 'Add Filename To array.
Count = Count + 1 'Increment counter
End If
End If
FileName = Dir ' Get another file name.
Loop
'remove the last empty element

ReDim Preserve Files(Count - 1)
ListFiles = Files()
End Function
Inputs:
Path = path to directory under which you would like to scan.

Returns:
Array of directories, or files found under path argument.












( enumfiles.html )- by Paolo Puglisi - Modifica del 17/12/2023