Results 1 to 4 of 4

Thread: Folders Question

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    How can i get all the sub folders present in a folder?

  2. #2
    Guest
    If you use a DirListBox and a FileListBox, this is how you get it:

    Code:
    Private Sub Dir1_Change()
    File1.Path = Dir1.Path
    'You should also add this same code to Dir1_Click
    End Sub
    
    Private Sub Command1_Click()
    For i = 0 To Dir1.ListCount - 1
    List1.AddItem Dir1.List(i)
    Next i
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    What I want is to have all the files and sub directories inside a folder upto the maximum depth.

    i.e.
    c:\windows\system\color
    c:\windows\media\songs
    c:\windows\favorites
    c:\windows\system32\drivers\vga\sound

    this is what i wanted to know.

  4. #4
    Guest
    Hehe...just found this code . It will list all SubDirectories in a Directory.

    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

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