VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get all subfolders of a given folder/drive. No API call; simple plain VB Code.

by Baldho (7 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 4th August 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Get all subfolders of a given folder/drive. No API call; simple plain VB Code.

API Declarations



Dim Folders As New Collection 'all subfolders

Rate Get all subfolders of a given folder/drive. No API call; simple plain VB Code.



    Dim tmpColl As New Collection 'temporary collection
    Dim strRetDir As String 'used to store what Dir will return
    Dim strTmpFolder As Variant 'for use with "for each...next"
    
    strRetDir = Dir(Folder & "\", vbDirectory) 'dummy starter to init strRetDir and Dir
    
    While Not strRetDir = vbNullString 'make a temporary list of folders in Folder
        If GetAttr(Folder & "\" & strRetDir) = vbDirectory And _
            strRetDir <> "." And _
            strRetDir <> ".." Then tmpColl.Add Folder & "\" & strRetDir
        strRetDir = Dir
    Wend
    
    For Each strTmpFolder In tmpColl 'Add each folder to the collection and call the sub for each of them.
        Folders.Add strTmpFolder
        getSubFolders CStr(strTmpFolder)
    Next
End Sub

'You can use the function this way:
'
'getSubFolders "D:\VB\tests"
'MsgBox Folders.Count
'
'Or this way too:
'
'getSubFolders "D:"
'MsgBox Folders.Count


Download this snippet    Add to My Saved Code

Get all subfolders of a given folder/drive. No API call; simple plain VB Code. Comments

No comments have been posted about Get all subfolders of a given folder/drive. No API call; simple plain VB Code.. Why not be the first to post a comment about Get all subfolders of a given folder/drive. No API call; simple plain VB Code..

Post your comment

Subject:
Message:
0/1000 characters