VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Using dir() to get a list of files and directories

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 :)

Rate Using dir() to get a list of files and directories

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

Download this snippet    Add to My Saved Code

Using dir() to get a list of files and directories Comments

No comments have been posted about Using dir() to get a list of files and directories. Why not be the first to post a comment about Using dir() to get a list of files and directories.

Post your comment

Subject:
Message:
0/1000 characters