|
-
Jun 16th, 2007, 09:16 AM
#1
New Member
Re: VB - List All The Files In A Directory
 Originally Posted by manavo11
The Dir way :
VB Code:
'Just add a listbox (List1)
Private Sub ListFiles(strPath As String, Optional Extention As String)
'Leave Extention blank for all files
Dim File As String
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
If Trim$(Extention) = "" Then
Extention = "*.*"
ElseIf Left$(Extention, 2) <> "*." Then
Extention = "*." & Extention
End If
File = Dir$(strPath & Extention)
Do While Len(File)
List1.AddItem File
File = Dir$
Loop
End Sub
Private Sub Form_Load()
ListFiles "C:\", "txt"
End Sub
Hello,
Thank for the above code, works a treat but I'm just wondering if anyone could help me out with a similarly easy way to do the same but to list the names of directories ("folders") within a directory?
So, the above code works great, it lists all the files of whatever type in say "C:\folder1".
What I need is code to list all the directories within "C:\folder1", not including subdirectories.
If anyone could help I would be much obliged.
Thanks in advance.
-
Jun 18th, 2007, 01:26 PM
#2
Re: VB - List All The Files In A Directory
 Originally Posted by RedJam
What I need is code to list all the directories within "C:\folder1", not including subdirectories.
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:\folder1\*.*"
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|