Using dir() to get a list of files and directories
![Visual Basic 6, or VB Classic Visual Basic 6, or VB Classic](https://www.fortypoundhead.com//assets/img/icons/v7/vb6.png)
instead of using the api and having to deal with nulls and UDT's and stuff, y not just use dir(), i have included 2 functions that return string arrays which contain all the files or directorys in the folder u specify. enjoy :)
Original Author: Mud Blud
Code
Public Function GetFolderList(Path As String) As String()
Dim Dirs() As String, Cnt As Integer
Dim I As String
I = Dir$(Path, vbDirectory)
Do While I <> ""
If (GetAttr(Path & I) And vbDirectory) = vbDirectory Then
If Trim$(I) = "." Or Trim$(I) = ".." Then GoTo DontAddItem
If Cnt = 0 Then ReDim Dirs(0) Else ReDim Preserve Dirs(0 To Cnt + 1)
Dirs(Cnt) = Path & Trim$(I)
Cnt = Cnt + 1
End If
DontAddItem:
I = Dir$()
Loop
GetFolderList = Dirs()
End Function
Public Function GetFileList(Path As String, Match As String) As String()
Dim Files() As String, Cnt As Integer
Dim I As String
I = Dir$(Path & Match)
Do While I <> ""
If Cnt = 0 Then ReDim Files(0) Else ReDim Preserve Files(0 To Cnt + 1)
Files(Cnt) = Path & Trim$(I)
Cnt = Cnt + 1
I = Dir$()
Loop
GetFileList = Files()
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.