?
Solved

Sub Folders

Posted on 2000-01-30
3
Medium Priority
?
135 Views
Last Modified: 2010-05-02
I need to know all the subfolder names within a folder, does anyone have an efficient way to do it?

Thanks in advance
0
Comment
Question by:ravisa
3 Comments
 
LVL 6

Expert Comment

by:VBGuru
ID: 2452482
Have a list box on the form. copy and paste the following code. click on the form in the run mode
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_DIR = &H18D
Private Const LB_RESETCONTENT = &H184
Private Const DDL_DIRECTORY = &H10
Private Const DDL_EXCLUSIVE = &H8000
Private Const DDL_FLAGS = DDL_EXCLUSIVE Or DDL_DIRECTORY
Private Sub Form_Click()
Dim numfound As Long
Dim searchPath As String
searchPath = "C:\windows\*.*"
Call SendMessage(List1.hwnd, LB_RESETCONTENT, 0, ByVal 0)
numfound = SendMessage(List1.hwnd, LB_DIR, DDL_FLAGS, ByVal searchPath)
MsgBox numfound & " directories found"
End Sub
0
 
LVL 2

Accepted Solution

by:
alokanant earned 150 total points
ID: 2452701
Here is a function which does the job -

Private Sub FindSubFolders(ByVal strPathName As String)
    Dim strSubFolders() As String
    Dim strTempSubFolder As String
    Dim intNumOfSubFolders As Integer
    Dim intSubFolderVount As Integer
       
    intNumOfSubFolders = -1
    strTempSubFolder = Dir(strPathName, vbDirectory)
    While Len(strTempSubFolder) <> 0
        intNumOfSubFolders = intNumOfSubFolders + 1
        ReDim Preserve strSubFolders(intNumOfSubFolders)
        strSubFolders(intNumOfSubFolders) = strTempSubFolder
        strTempSubFolder = Dir()
    Wend
   
'   Prepare the list of sub folders
    For intSubFolderCount = 0 To intNumOfSubFolders
        strTempSubFolder = strTempSubFolder & ", " & strSubFolders(intSubFolderCount)
    Next intSubFolderCount
       
    MsgBox "The number of sub folders in " & strPathName & " are " & (intNumOfSubFolders + 1) & ". They are - " & strTempSubFolder
End Sub

hth
alok
0
 

Author Comment

by:ravisa
ID: 2477157
Thanks very much
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question