Okay, i puzzled over this for some time, and i have finally worked out:

How To List the Contents of a Directory, without using Scripting.FileSystemObject

Dir() and Dir$() are most often used to check if a file exists:

Dir("c:\existingFile.txt", vbNormal)
-> "c:\existingFile.txt"
Dir("c:\nonExistingFile.txt", vbNormal)
-> ""

But if you pass in some kind of wildcard, or directory name, together with the attributes you want, Then repeatedly call Dir without any parameters, it lists the entire directory:

Dir("C:\", vbDirectory)
-> .
-> ..
-> "My Documents"
-> "Program Files"
-> "Windows"
-> ""

and returns a zero length string at the end of the listing

so you can capture this into an array, and redim preserve array(ubound(array)+1) it as many times as needed


for implementations requiring listing of many files, it might be advisable to either:

create a counter
Dir() until "" is obtained, incrementing the counter each time
create an array of length(counter)
repeat the Dir() and fill the array


use a linked list


either method is guaranteed to be faster than re-dimming an array a few thousand times