Try using the next approach, please:
Sub LoopAllFilesInAFolderAndSubfolders()
Dim FSO As Object, foldName As String
'Create FSO object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set the folder name to a variable
foldName = "E:\Downloads\data\ADVANCED\2020\Feb\1\"
'Call the recursive itSubFolders Sub, which makes the job:
itSubFolders FSO.GetFolder(foldName)
End Sub
And the recursive Sub extracting all files in subfolders:
Sub itSubFolders(FSOFolder As Object)
Dim objSubfold As Object, objFile As Object
'Iterate between al subfolders
Sub itSubFolders(FSOFolder As Object)
Dim objSubfold As Object, objFile As Object
'Iterate between al subfolders
For Each objSubfold In FSOFolder.SubFolders
itSubFoldersAndFiles objSubfold
Next
'iterate for files
For Each objFile In FSOFolder.Files
'Debug.Print objFile.path
itSubFolders objFile 'I think, the code should send the file path as parameter, to the existing Function/Sub
Next
End Sub
You can test the above recursive Sub, un commenting the line 'Debug.Print "Subfolder: " & objFile.path
and commenting the following one. It will return in Immediate Window all files path.
Note: The above recursive Sub
works also for all subfolders inside subfolders...