Private Sub Command1_Click()
    Dim fs As FileSystemObject
    Dim f As Folder
    Dim folders As folders
    Dim i As Long
    Dim old As Long
    Dim cur As Long
    
    Set fs = New FileSystemObject
    old = 0
    lstResult.AddItem "C:\"
    lstResultAll.AddItem "C:\"
    cur = lstResult.ListCount    While cur > old
        While cur > old
            Set f = fs.GetFolder(lstResultAll.List(old))
            
            Set folders = f.SubFolders
            
            For Each f In folders
                lstResult.AddItem f.Name
                lstResultAll.AddItem (f.Path) & "\"
            Next
            
            old = old + 1
        
        Wend
        cur = lstResultAll.ListCount
    Wend
    
End Sub 试试这个代码。需要再添加一个名为lstResultAll的ListBox

解决方案 »

  1.   

    那怎么用treeview控件按照节点类型那样的显示出目录名呢(与原来的目录结构相对应),这样比较一目了然
      

  2.   


    sub listfolder(fd as folder)
    dim sfd as folder
    for each sfd in fd.subfolders
        treeview.nodes.add fd.path,tvwchild,sfd.path,sfd.name
        listfolder sfd
    next
    end sub
      

  3.   

    set fd=fs.getfolder("c:\")
    treeview.nodes,add ,,fd.path,fd.path
    listfolder fd
      

  4.   

    飞龙兄,这段代码出错了,Byref参数类型不符