Looping through files - make recursive!? Help please
Looping through files - make recursive!? Help please
Mummy maze full crack. Re: Looping through Outlook folders and subfolders, returning numberofe-mails Thanks very much, unfortunately I received an error: You cannot call a method on a null-valued expression. Loop Through Subfolders using FileSystemObject A common Excel VBA requirement is to work with different files and folders of a directory. This will continue until no more subfolders can be found. At that point, the function will loop back, and start working its way through Subfolder B. Miracle box usb serial port driver. Furthermore, it will dutifully keep working until it has gone through each and every subfolder and sub-subfolder and sub-sub-subfolder and – well, until every last file has been listed.
I have a loop which runs through the files in a folder and subfolder. I need this to be recursive (so it runs through all subfolders until they are all done).I have never done any recursive coding so would really appreciate being shown how! Or if there is better code then I am using, please make any suggestions.
R Loop Through Subdirectories
CODE
R Loop Through Subfolders
Sub LoopFoldersListFiles(path As String)
'Loops thru sub folders, listing files
'Application.ScreenUpdating = False
Dim fso As New FileSystemObject
Dim f As Folder, sf As Folder, r As Integer, fname As String
'Get a reference to the Folder object.
Set f = fso.GetFolder(path)
'Iterate through subfolders.
r = 1
On Error Resume Next
For Each sf In f.SubFolders
fname = path & sf.name & '*.*'
FileName = Dir$(fname)
Do While FileName <> '
Debug.Print path & sf.name & ' & FileName
r = r + 1
FileName = Dir$()
Loop
Next
End Sub
'Loops thru sub folders, listing files
'Application.ScreenUpdating = False
Dim fso As New FileSystemObject
Dim f As Folder, sf As Folder, r As Integer, fname As String
'Get a reference to the Folder object.
Set f = fso.GetFolder(path)
'Iterate through subfolders.
r = 1
On Error Resume Next
For Each sf In f.SubFolders
fname = path & sf.name & '*.*'
FileName = Dir$(fname)
Do While FileName <> '
Debug.Print path & sf.name & ' & FileName
r = r + 1
FileName = Dir$()
Loop
Next
End Sub