Search Tools Links Login

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

Visual Basic 6, or VB Classic

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


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
I = Dir$()
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$()
GetFileList = Files()
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 98 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.