以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请教 做一个我的电脑的目录树  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=98705)

--  作者:ljh29206
--  发布时间:2017/4/5 15:17:00
--  请教 做一个我的电脑的目录树
内部函数
Dim tr As WinForm.TreeNode = args(0)

If FileSys.DirectoryExists(tr.name)  Then
For Each dir As String In FileSys.GetDirectories(tr.name)
    Dim cd As WinForm.TreeNode =  tr.Nodes.Add(dir)
    Functions.Execute("AddChildren",cd)
Next
ElseIf FileSys.FileExists(tr.name) Then
    Dim cd As WinForm.TreeNode =  tr.Nodes.Add(tr.name)
End If

目录树生成代码

Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
For Each DInfo As IO.DriveInfo In IO.DriveInfo.GetDrives
    If dinfo.Isready Then
        nd = tv.Nodes.Add(dinfo.name)
        For Each dir As String In  FileSys.GetDirectories(dinfo.name)
            Dim  cd As WinForm.TreeNode = nd.Nodes.Add(dir,dir.Replace(dinfo.name,""))
          Functions.Execute("AddChildren",nd)
        Next
        For Each dir As String In  FileSys.GetFiles(dinfo.name)
            Dim  cd As WinForm.TreeNode = nd.Nodes.Add(dir,dir.Replace(dinfo.name,""))
        Next
    End If
Next

求指导 哪里错了
[此贴子已经被作者于2017/4/5 15:27:33编辑过]

--  作者:有点蓝
--  发布时间:2017/4/5 16:18:00
--  
代码没有问题,只是没有权限读取一些系统的关键目录。

Dim tr As WinForm.TreeNode = args(0)

If FileSys.DirectoryExists(tr.name)  Then
    try
        For Each dir As String In FileSys.GetDirectories(tr.name)
            Dim cd As WinForm.TreeNode =  tr.Nodes.Add(dir)
            Functions.Execute("AddChildren",cd)
        Next
        catch
    End try
ElseIf FileSys.FileExists(tr.name) Then
    Dim cd As WinForm.TreeNode =  tr.Nodes.Add(tr.name)
End If

--  作者:有点色
--  发布时间:2017/4/5 16:18:00
--  

Dim tr As WinForm.TreeNode = args(0)

If FileSys.DirectoryExists(tr.name)  Then
    For Each dir As String In FileSys.GetDirectories(tr.name)
        Dim info As new fileinfo(dir)
        If info.Hidden = False Then
            Dim cd As WinForm.TreeNode =  tr.Nodes.Add(dir, filesys.GetName(dir))
            Functions.Execute("test",cd)
        End If
    Next
End If

For Each dir As String In  FileSys.GetFiles(tr.name)
    Dim  cd As WinForm.TreeNode = tr.Nodes.Add(dir, FileSys.GetName(dir))
Next

 

 

----------------

 

Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
For Each DInfo As IO.DriveInfo In IO.DriveInfo.GetDrives
    If dinfo.Isready AndAlso dinfo.name = "d:\\" Then
        nd = tv.Nodes.Add(dinfo.name)
        Functions.Execute("test",nd)
    End If
Next


--  作者:ljh29206
--  发布时间:2017/4/5 16:43:00
--  
谢谢2位,再试下
--  作者:jyh7081
--  发布时间:2017/5/12 11:07:00
--  

有点色老师,我把路径改成子目录,就没反应了,只能针对根目录吗?(函数已添加)

 

Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
For Each DInfo As IO.DriveInfo In IO.DriveInfo.GetDrives
    If dinfo.Isready AndAlso dinfo.name = "d:\\aa\\" Then
        nd = tv.Nodes.Add(dinfo.name)
        Functions.Execute("test",nd)
    End If
Next

 

附件:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:资源管理.table


--  作者:有点色
--  发布时间:2017/5/12 11:11:00
--  

 如果你要某个路径下的,这样写

 

Dim tv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
nd = tv.Nodes.Add("g:\\data\\")
Functions.Execute("test",nd)


--  作者:湛江智
--  发布时间:2019/6/12 17:06:00
--  回复:(有点色) 如果你要某个路径下的,这样写...
 坛主,要实现双击目录树节点,打开文件,代码怎么写呢?
--  作者:有点甜
--  发布时间:2019/6/12 17:20:00
--  
以下是引用湛江智在2019/6/12 17:06:00的发言:
 坛主,要实现双击目录树节点,打开文件,代码怎么写呢?

 

msgbox(e.node.path) 然后改成路径打开即可

 

http://www.foxtable.com/webhelp/scr/0353.htm