Hi all,
I'm trying to figure out a way to list only the first level of folders in a file structure. I'm accustomed to using the GetFolder method but how to do only one level is the question. For instance, if I had the following folder structure:
C:\Base
C:\Base\FolderA
C:\Base\FolderA\Folder1
C:\Base\FolderA\Folder2
C:\Base\FolderB
C:\Base\FolderB\Folder3
and I set the macro to scan C:\Base then it would return:
C:\Base\FolderA
C:\Base\FolderB
Does that make sense? Please note that I know how to list the files. But I want to list the folders.
Right now I have my macro as something like:
Set FSO = CreateObject("scripting.filesystemobject")
Set theBaseFolder = FSO.GetFolder(theBaseFolderName)
For Each ofTheFolders in theBaseFolder.SubFolders
But that's where I get stuck. Right now this returns ALL of the subfolders. I could pull the path of each object as a string and search for the number of "\" contained but that is a clunky solution for something that seems like it should be fairly clean.
Suggestions? Thoughts?
I'm not really that great of a programmer so a little explanation would be helpful. Otherwise I will play with the code suggestions until they make sense to me.
Thanks!
I'm trying to figure out a way to list only the first level of folders in a file structure. I'm accustomed to using the GetFolder method but how to do only one level is the question. For instance, if I had the following folder structure:
C:\Base
C:\Base\FolderA
C:\Base\FolderA\Folder1
C:\Base\FolderA\Folder2
C:\Base\FolderB
C:\Base\FolderB\Folder3
and I set the macro to scan C:\Base then it would return:
C:\Base\FolderA
C:\Base\FolderB
Does that make sense? Please note that I know how to list the files. But I want to list the folders.
Right now I have my macro as something like:
Set FSO = CreateObject("scripting.filesystemobject")
Set theBaseFolder = FSO.GetFolder(theBaseFolderName)
For Each ofTheFolders in theBaseFolder.SubFolders
But that's where I get stuck. Right now this returns ALL of the subfolders. I could pull the path of each object as a string and search for the number of "\" contained but that is a clunky solution for something that seems like it should be fairly clean.
Suggestions? Thoughts?
I'm not really that great of a programmer so a little explanation would be helpful. Otherwise I will play with the code suggestions until they make sense to me.
Thanks!