|
-
Jun 16th, 2007, 09:16 AM
#4
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.
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
|