VB - List all subfolders in a specific folder
Add a reference to the "Microsoft Scripting Runtime":
VB Code:
Private Sub Command1_Click()
Dim strStartPath As String
strStartPath = "C:\" 'ENTER YOUR START FOLDER HERE
ListFolder strStartPath
End Sub
Private Sub ListFolder(sFolderPath As String)
Dim FS As New FileSystemObject
Dim FSfolder As Folder
Dim subfolder As Folder
Dim i As Integer
Set FSfolder = FS.GetFolder(sFolderPath)
For Each subfolder In FSfolder.SubFolders
DoEvents
i = i + 1
Debug.Print subfolder
Next subfolder
Set FSfolder = Nothing
MsgBox "Total sub folders in " & sFolderPath & " : " & i
End Sub
Re: VB - List all subfolders in a specific folder
VB Code:
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set fo = fs.GetFolder("c:\temp\)
For Each x In fo.SubFolders
Debug.Print x.Name
Next
Re: VB - List all subfolders in a specific folder
Another way
vb Code:
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 DDL_DIRECTORY = &H10
Private Const DDL_ARCHIVE = &H20
Private Const DDL_EXCLUSIVE = &H8000
Private Sub Command1_Click()
List1.Clear
SendMessage List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_DIRECTORY, ByVal "C:\Windows\*.*"
End Sub