Listing files with a For...Each loop : FileSystemObject « File Path « VBA / Excel / Access / Word






Listing files with a For...Each loop

 
     Sub FileListDemo()
         Dim objFSO As Object
         Dim objFolder As Object
         Dim objFile As Object
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         Set objFolder = objFSO.GetFolder("C:\")
         For Each objFile In objFolder.Files
           Debug.Print objFile.name
         Next objFile

     End Sub

 








Related examples in the same category

1.Copying a File
2.Display selected file information
3.Delete file by using FileSystemObject
4.Delete Folder by using FileSystemObject
5.Recursive Search using the FileSystemObject Model