Returns a Files collection consisting of all File objects contained in the specified folder, including those with hidden and system file attributes set.
Syntax
object.Files
The object is always a Folder object.
Examples
The following code illustrates the use of the Files property.
Sub ShowFileList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
s = s & f1.Name
s = s & vbCrLf
Next
Debug.Print s
End Sub
Run the following code in the Immediate Window to test this macro:
ShowFileList "D:\TestFolder"
This macro lists all files of TestFolder folder (exclude sub folder), if you want to list all files (include sub folders), read this: Excel Macro: List All Files in Folders and Subfolders
Result:
hidden.txt
hidden_readonly.txt
readonly.txt