How would I read all sub folders of a folder, and then all files in the sub folders?
Printable View
How would I read all sub folders of a folder, and then all files in the sub folders?
Here is a thread about that:
LINK
You'll just need to remove all Filename related stuff from that, cause you don't want to search, you want to list everything.
Run-timer error '91': Object variable or With block variable not setVB Code:
Public Function ReadFolder(Folder As String) As Object ReadFolder = CreateObject("Scripting.FileSystemObject").GetFolder(Folder).Subfolders End Function
What's that? You did that? thats not from the code in the thread.
You can't create and object and access its methods at the same time. :eek:
Try
VB Code:
Dim fso as Object, f as Object, FolderName as String FolderName = App.Path & "\SomeDir" Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(FolderName)
PS: Don't use the CreateObject stuff now, you will add it at the end.
Now add the reference to Microsoft Scripting Runtime, and declare it like this:
And Instanciate like this:VB Code:
Dim Fso As Scripting.FileSystemObject
VB Code:
Set fso = New Scripting.FileSystemObject
I thought vb would have parsed it as:/ oh well. Thanks for the help. Got it workin.VB Code:
Public Function ReadFolder(Folder As String) As Object ReadFolder = CreateObject("Scripting.FileSystemObject") ReadFolder = ReadFolder.GetFolder(Folder).Subfolders ReadFolder = ReadFolder.Subfolders End Function