|
Question : How to create a list of sub folders?
|
|
Is it possible to create a list(array) of all the sub folders in a given folder in VBA?
for example in the following tree I need to have an array that contains all the sub folders under parts directory.
C:\- |__parts__ | |__sub folder 1 | |__sub folder 2 | |__sub folder 3 |__Drawing
any kind of help is much appreciated.
|
|
Answer : How to create a list of sub folders?
|
|
Try this:
Set objFSO = CreateObject("Scripting.FileSystemObject") strSourceFolder = "C:\Parts" For Each objSubFolder In objFSO.GetFolder(strSourceFolder).SubFolders strSubFolders = strSubFolders & ";" & objSubFolder.Name Next If Len(strSubFolders) > 0 Then strSubFolders = Mid(strSubFolders, 2) arrSubFolders = Split(strSubFolders, ";") ' Now you can iterate the array to see the names Else MsgBox "There are no subfolders in " & strSourceFolder End If
Regards,
Rob.
|
|
|