Dim fso As Scripting.FileSystemObject
Dim lFolder As Scripting.Folder
Dim lFile As Scripting.File
Set fso = New Scripting.FileSystemObject
Set lFolder = fso.GetFolder("C:\")
For Each lFile In lFolder.Files
Debug.Print lFile.Name
Next
Or, without FSO
Code:
Dim rslt As String
rslt = Dir("C:\")
Do
Debug.Print rslt
rslt = Dir
Loop While rslt <> ""
Just to be on the safe side, you should check for a string length of 0 before entering the loop. If you don't and there are no files in the directory, the program will error and crash.
Dim rslt As String
rslt = Dir("C:\")
Do While rslt <> ""
Debug.Print rslt
rslt = Dir
Loop
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.