Results 1 to 2 of 2

Thread: VB Directories

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    1
    I am trying to write a function for VB 6 which returns an array of every directory in a path. I know that this involves recursive coding, but everything I try returns in error messages and a load of crap.

    Anybody who can help me with this, please could you e-mail me @ [email protected]

    Many thanks.

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Hi,

    try the code below. It receives a listbox and the startpath as parameters and fills all the subdirs beginning with startpath in the listbox.

    Good Luck!
    Roger

    Sub readdir(fillinlist As ListBox, startpath)

    On Error Resume Next

    Dim found As String
    Dim paths() As String
    Dim pathcount As Long
    Dim i As Long

    startpath = Trim$(startpath)
    If Right$(startpath, 1) <> "\" Then startpath = startpath & "\"

    found = Dir(startpath & "*.*")

    Do While Len(found) > 0
    fillinlist.AddItem startpath & found
    found = Dir
    Loop

    pathcount = 0

    found = Dir(startpath, vbDirectory)

    Do While Len(found) > 0
    If found <> "." And found <> ".." Then

    pathcount = pathcount + 1

    If pathcount = 1 Then
    ReDim paths(1 To 1)
    Else
    ReDim Preserve paths(1 To pathcount)
    End If

    paths(pathcount) = startpath & found
    End If

    found = Dir

    Loop

    For i = 1 To pathcount
    readdir fillinlist, paths(i)
    Next

    End Sub

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