Results 1 to 2 of 2

Thread: Loading Directory Conents Into Array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    14

    Post

    How would I load a directorys contents into an array cuase im trying to list the documents list thats in windows start menu in a menu and all I really need is to be able to list the contents in an array and I can do the rest.. Thanx

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the Dir Function:
    Code:
    Private Sub Command1_Click()
        Dim aDir As Variant
        Dim iIndex As Integer
        
        aDir = ListDir("C:\*")
        For iIndex = 0 To UBound(aDir)
            List1.AddItem aDir(iIndex)
        Next
    End Sub
    
    Private Function ListDir(ByVal sPath As String) As Variant
        Dim aList() As String
        Dim sDir As String
        Dim iIndex As Integer
        
        sDir = Dir(sPath)
        While Len(sDir)
            ReDim Preserve aList(iIndex)
            aList(iIndex) = sDir
            iIndex = iIndex + 1
            sDir = Dir
        Wend
        ListDir = aList
    End Function
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width