by Mud Blud (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
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 :)
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