Results 1 to 5 of 5

Thread: A little help here please..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    99
    Say you have C:\folders, inside that dir are folders called "Blah1", "Blah2" etc...

    How could you load each folder name (x amount of folders) into a listbox?
    ___________________________
    Chris

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'using fso
    Code:
    Option Explicit
    
    Sub ShowFolderList(folderspec)
    
        Dim fs As Object
        Dim f, f1, s, sf
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
        Set sf = f.SubFolders
        For Each f1 In sf
            s = f1.Name
    
            List1.AddItem s
            s = s & vbCrLf
        Next
       
    End Sub
    
    
    Private Sub command1_Click()
        Call ShowFolderList("C:\")
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    Dir Function:
    Code:
    Dim myst
    Dim MyName As String
    Dim MyPath As String
    ' Display the names in C:\ that represent directories.
    MyPath = "c:\windows\"   ' Set the path.
    MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
    Do While MyName <> ""   ' Start the loop.
       ' Ignore the current directory and the encompassing directory.
       If MyName <> "." And MyName <> ".." Then
          ' Use bitwise comparison to make sure MyName is a directory.
          If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
             List1.AddItem MyName ' Display entry only if it
          End If   ' it represents a directory.
       End If
       MyName = Dir   ' Get next entry.
    Loop
    [Edited by gwdash on 09-17-2000 at 06:20 PM]
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4
    Guest
    Try this:

    Code:
    Sub DirMap(ByVal Path As String, List As ListBox)
        On Error Resume Next
        Dim i, j, x As Integer 'All used as counters
        Dim Fname(), CurrentFolder, Temp As String
        Temp = Path
        If Dir(Temp, vbDirectory) = "" Then Exit Sub 'if there arent any sub directories the exit
        CurrentFolder = Dir(Temp, vbDirectory)
        'First get number of folders (Stored in
        '     i)
    
    
        Do While CurrentFolder <> ""
    
    
            If GetAttr(Temp & CurrentFolder) = vbDirectory Then
    
    
                If CurrentFolder <> "." And CurrentFolder <> ".." Then
                    i = i + 1
                End If
            End If
            CurrentFolder = Dir
        Loop
        ReDim Fname(i) 'Redim the array With number of folders
        'now store the folder names
        CurrentFolder = Dir(Temp, vbDirectory)
    
    
        Do While CurrentFolder <> ""
    
    
            If GetAttr(Temp & CurrentFolder) = vbDirectory Then
    
    
                If CurrentFolder <> "." And CurrentFolder <> ".." Then
                    j = j + 1
                    Fname(j) = CurrentFolder
                    List.AddItem Temp & Fname(j)
                End If
            End If
            CurrentFolder = Dir
        Loop
        ' For each folder check to see there are
    
    
    '     sub folders
    
    
        For x = 1 To i
            Call DirMap(Temp & Fname(x) & "\", List)
        Next
    End Sub
    
    
    
    Usage:
    
    Private Sub Command1_Click()
        Call DirMap("C:\Windows\", List1)
        'Must have "\" at the end of the path
    End Sub

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    there is also another example, if you search for Start Menu, posted by Zaei, you will find it.

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