'通过过System.IO.DirectoryInfo对象可以查阅目录信息,下面是遍历一个文件夹下所有层次的子文件夹,如果只检查下一层目录就更简单了。
成都创新互联自2013年起,先为监利等服务建站,监利等地企业,进行企业商务咨询服务。为监利企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folder = New System.IO.DirectoryInfo("D:\Documents")
Dim items = getemptyfolder(folder)
For Each item In items
Console.WriteLine(item.FullName)
Next
End Sub
Function getemptyfolder(ByVal 谨胡folder As System.IO.DirectoryInfo) As System.IO.DirectoryInfo()
Dim 稿毕items As New List(Of System.IO.DirectoryInfo)
If folder.EnumerateFiles().Count = 0 Then
items.Add(folder)
End If
Dim subfolders = folder.EnumerateDirectories()
For Each subfolder In subfolders
items.AddRange(getemptyfolder(subfolder)) '查询树形目录结构类型数据用递归法实现
祥敬拦 Next
Return items.ToArray()
End Function
'还是学c#语言吧,我发觉同样一个数组,c#功能多的多,vb点虐 没几条方法可用。
TreeView1.Nodes.Add , , "a", "主节点一" ',后面举察有有两个图标参正运茄数 '节点编号1
TreeView1.Nodes.Add 1, tvwChild, "s", "子节点一" '节点编号2
TreeView1.Nodes.Add , , "d", "主节点二" '节点编号3
TreeView1.Nodes.Add 3, tvwChild, "f", "子节点二" '节悄虚点编号4
你说的“树形菜单”是指下拉菜单(可以有子菜单)吗?如果是,VB点虐 提供了MenuStrip控件,在工让悄扮具箱里能找到,直接就在对应位置打字就可以坦灶了,完全是“所见即所运李得”。
给明并你一段我曾经写的代码,主要是生成TreeView的节点!有什么不懂的地方你就提衫激!
Public Sub InitializeTreeView(ByVal strvXL As TreeView, ByVal vrsRecordTwo As DataSet)
Dim treBaseNodeOne As TreeNode
Dim treBaseNodeTwo As TreeNode
Dim strDWDM As String
m_rsRecordTwo = g_clsSybase.SelectSC_PD_SBCSB1()
'或槐袜查找供电局信息
g_clsSybase.SelectRS_ZZJG_ZZJGDMB(m_rsRecordOne)
'添加根节点
Do While m_rsRecordOne.Read
strDWDM = m_rsRecordOne.GetString(0) '获取单位代码
treBaseNodeOne = New TreeNode
treBaseNodeOne.Text = m_rsRecordOne.GetString(1).Trim() '获取单位名称
treBaseNodeOne.Name = m_rsRecordOne.GetString(1)
treBaseNodeOne.Tag = ""
strvXL.Nodes.Add(treBaseNodeOne)
'添加树结构第二层
Dim drsTwo() As DataRow
drsTwo = m_rsRecordTwo.Tables(0).Select("SSDW='" strDWDM "' and SC__XLBM is null")
For Each dr As DataRow In drsTwo
treBaseNodeTwo = New TreeNode
treBaseNodeTwo.Text = dr.Item("XLMC").ToString.Trim
treBaseNodeTwo.Name = dr.Item("XLMC")
treBaseNodeTwo.Tag = dr.Item("XLBM")
treBaseNodeOne.Nodes.Add(treBaseNodeTwo)
Next
Loop
m_rsRecordOne.Close()
End Sub