get the name of sub dir

User avatar
sal21
PlatinumLounger
Posts: 4169
Joined: 26 Apr 2010, 17:36

get the name of sub dir

Post by sal21 »

based this path:

"C:\Lavori_Vb6\COMUNI\STEMMI\"

how to retrieve the name of each subdir?

attached the structure

in my case are 20 subdir
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 75751
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: get the name of sub dir

Post by HansV »

Code: Select all

Sub ListSubfolders()
    Dim strFolder As String
    Dim strSubfolder As String
    ' Path must end in \
    strFolder = "C:\Lavori_Vb6\COMUNI\STEMMI\"
    strSubfolder = Dir(strFolder & "*.*", vbDirectory)
    Do While strSubfolder <> ""
        Select Case strSubfolder
            Case ".", ".."
                ' Skip these
            Case Else
                Debug.Print strSubfolder
        End Select
        strSubfolder = Dir
    Loop
End Sub
Regards,
Hans

User avatar
p45cal
2StarLounger
Posts: 100
Joined: 11 Jun 2012, 20:37

Re: get the name of sub dir

Post by p45cal »

or:

Code: Select all

Sub GetSubFolderNames()
Set fso = CreateObject("Scripting.FileSystemObject")
For Each MySubFolder In fso.GetFolder("C:\Lavori_Vb6\COMUNI\STEMMI").SubFolders
    Debug.Print MySubFolder.Name
Next MySubFolder
End Sub