JustCode : Loop all files and folders

I have started using this allot in the last few months. This JustCode example will show you all the files and folders in a specific folder.

LoopFolders(“c:\temp”)
 
Sub LoopFolders(sFullPath)
 Dim oFolder,oSubFolder,oFSO,oFile
 
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
 
If oFSO.FolderExists(sFullPath) Then
 Set oFolder = oFSO.GetFolder(sFullPath)
 
For Each oFile In oFolder.Files
 debug.Log(oFolder.Path + “” + oFile.Name)
 Next
 
For each oSubFolder in oFolder.SubFolders
 debug.Log(“Folder:”+ oSubFolder.Name)
 LoopFolders(oSubFolder.Path)
 Next
 
End If
 
Set oFSO = null
 Set oFolder = null
 Set oFile = null
 End Sub

Leave a Comment