Thursday, July 8, 2010

List files and folders - FSO

Option Explicit
Dim X As New FileSystemObject

Dim F As Folder
Set F = X.GetFolder( "d:\data" )
GetFolderList F


Sub GetFolderList(aFolder As Folder)
'Put code here if you want to stop the search If SearchStop = False Then Exit Sub
For Each tempFile In aFolder.Files
Print tempFile.Name
Next

Dim tempFolder As Folder
For Each tempFolder In aFolder.SubFolders
Print tempF.ParentFolder & "\"; tempF.Name
GetFolderList tempFolder
Next
End Sub