Listing all files in a directory


Posted by JAIME on December 07, 2001 8:57 AM

Is there a way listing all the files of a directory in an excel sheeet?



Posted by Dank on December 07, 2001 9:21 AM

You can use the Filesearch object e.g.

Sub GetFiles()
Dim lngCellCounter As Long

With Application.FileSearch
.NewSearch
.LookIn = "C:\TEMP"
.SearchSubFolders = True 'Set this to false if you don't want subfolders included
.Execute
For lngCellCounter = 1 To .FoundFiles.Count
Cells(lngCellCounter, 1) = .FoundFiles(lngCellCounter)
Next lngCellCounter
End With


End Sub

Hope it helps,
Daniel.