Recursively access subfolder files inside a folder

This is actually a well-solved problem. Recursion means that you create a self-referencing function (a function that calls itself). In your case you’d make the function call itself for each subfolder of the current folder.

TraverseFolders objFso.GetFolder(strPath)

Function TraverseFolders(fldr)
  ' do stuff with the files in fldr here, or ...

  For Each sf In fldr.SubFolders
    TraverseFolders sf  '<- recurse here
  Next

  ' ... do stuff with the files in fldr here.
End Function

Leave a Comment