Private Sub Command1_Click()
    Dim fs As New FileSystemObject ' 建立 FileSystemObject
    Dim fd As Folder ' 定义 Folder 对象
    Dim sfd As Folder
    Set fd = fs.GetFolder("c:\")
    ListFolder fd
    End Sub    Sub ListFolder(fd As Folder)
    Dim sfd As Folder
    For Each sfd In fd.SubFolders
    Debug.Print sfd.Path
    List1.AddItem sfd.Path
    ListFolder sfd ' 以 sfd 为参数,递归调用
    Next
    End Sub

解决方案 »

  1.   

    自己改不就得了??
    看看MSDN,你既然会用FSO,还有什么解决不了的
    不就是递归吗:
      

  2.   

    private function AddTreeNode(xPNode as Node,strFolder as String) as Node
        set AddTreeNode=xpnode.add strFolder,……
    end funciton
    每次得到的父文件夹的节点AddTreeNode作为子文件夹的xPNode
      

  3.   

    大致如下,没有vb,没调,你自己调吧。
    dim lCount as longPrivate Sub Command1_Click()
        Dim fs As New FileSystemObject ' 建立 FileSystemObject
        Dim fd As Folder ' 定义 Folder 对象
        Dim sfd As FolderlCount=1
    tvw.nodes.add ,,"k" & lCount,"c:\"
        Set fd = fs.GetFolder("c:\",lCount)
        ListFolder fd
    End SubSub ListFolder(fd As Folder,byval pCount as long)
        Dim sfd As Folder
        For Each sfd In fd.SubFolders
        Debug.Print sfd.Path
        List1.AddItem sfd.Path
    lcount=lcount+1
    tvw.nodes.add "k" & pcount,tvwChild,"k" & lCount,sfd.path    ListFolder sfd,lcount ' 以 sfd 为参数,递归调用
        Next
    End Sub
    这里,tvw是一个treeview控件
      

  4.   

    不是了,我从没读过他的书,只是对treeview用的不太好了,自己改了一下,总是有些问题,所以才求救了,另外呢?递归的顺序不知道,所以用treeview时总是有问题,无法判断添加的tree是哪一个ROOT 里的.
      

  5.   

    按照我上面的思路基本没问题,实际就是为每一个文件设置一个文件号,所以lCount是模块级公有的,然后以每个文件的文件号作为k值,但因为treeview的key不能为数字,所以在前面加了一个字符区别。
      

  6.   

    '非常感谢这位朋友
    '这位朋友,写得很不错,不过有点差错现将调试完成的,代码更改如下:
    Dim lCount As LongPrivate Sub Command1_Click()
        Dim fs As New FileSystemObject ' 建立 FileSystemObject
        Dim fd As Folder ' 定义 Folder 对象
        Dim sfd As Folder
    lCount = 1
    tvw.nodes.Add , , "k" & lCount, "d:\"
        '将原有的代码:
        'Set fd = fs.GetFolder("d:\",.lCount)
        'ListFolder fd
        '改成下面的代码就可以了
        Set fd = fs.GetFolder("d:\")
        ListFolder fd, lCount
    End SubSub ListFolder(fd As Folder, ByVal pCount As Long)
        Dim sfd As Folder
        For Each sfd In fd.SubFolders
        Debug.Print sfd.Path
        List1.AddItem sfd.Path
    lCount = lCount + 1
    tvw.nodes.Add "k" & pCount, tvwChild, "k" & lCount, sfd.Name    ListFolder sfd, lCount ' 以 sfd 为参数,递归调用
        Next
    End Sub
    'tvw为treeview控件
      

  7.   

    动态读取到TreeView:
    http://www.fantasiasoft.net/Zyl910/DirList.zip
      

  8.   

    点哪一个Node,再对其子节点枚举比较好。就像CSDN的导航栏
      

  9.   

    回复人: pigpag(噼里啪啦) ( ) 信誉:117  2004-01-19 11:59:00  得分:0 
     
     
      点哪一个Node,再对其子节点枚举比较好。就像CSDN的导航栏
      
     
    =================================我的程序就是的
      

  10.   

    to goldstar3000(金星) :
    sorry,没有调试就给你了,手里倒是有vb了,但是我从来没有用过fso,所以,呵呵,找了半天没有找到fso的对象是哪个,所以,没有调就给你了。
    反正你自己也调好了,目的达到了吧?
      

  11.   

    动态读取到TreeView:
    http://www.fantasiasoft.net/Zyl910/DirList.zip
      

  12.   

    fso文件系统,FileSystemObject对象是引用的所以找不到了,哪几位朋友是代码所举的例子不是最好的,哪两个代码我都看过,很繁索,所以我没有使用.而且会有问题的,不过非常感谢各位朋友的.但不知道哪位朋友的动态装裁,有多少代码?我认这代码是最优的,
    自己又学了一招了,在这段代码中上涉及到了参数在过程中的传递其中lcount就是要参数,刚学的朋友,一定要学一学参数传递,