imports System.IO
imports System.Data
'imports System.Data.linq
'imports System.Data.linq.MapPing
imports System.windows.Forms
Public Class Form1
Private Sub TreeVIEw1_AfterSelect(ByVal sender As System.Object,ByVal e As System.windows.Forms.TreeVIEwEventArgs) Handles TreeVIEw1.AfterSelect
If Not TreeVIEw1.Selectednode Is nothing Then
MessageBox.Show(TreeVIEw1.Selectednode.Text)
End If
End Sub
Public Sub AddDirectory(ByVal strFatherPath As String,ByVal strPath As String,ByVal nodeFather As TreeNode)
Dim IDir As IO.Directory
Dim IDirInfo As IO.DirectoryInfo
Dim i As Integer
Dim node As New TreeNode
'先添加本目录,从文件夹路径分析出文件夹名称
node.Text = Strings.Replace(strPath,strFatherPath & "\","",1)
'为单个节点指定节点未被选中时显示的图标
node.ImageIndex = 1
'为单个节点指定节点被选中时显示的图标
node.SelectedImageIndex = 2
nodeFather.Nodes.Add(node)
Application.DoEvents()
Try
Dim str() As String = IO.Directory.GetDirectorIEs(strPath)
'遍历该目录的子文件夹
For i = 0 To str.GetUpperBound(0)
AddDirectory(strPath,str(i),node)
Next
Catch ex As Exception
DeBUG.Writeline(ex.Message)
End Try
node = nothing
IDir = nothing
End Sub
Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click
Dim IDir As IO.Directory
Dim node As New TreeNode
'先把C盘添加到树中
TreeVIEw1.Nodes.Clear()
node.ImageIndex = 0
node.Text = "PC_Code"
node.SelectedImageIndex = -1
TreeVIEw1.Nodes.Add(node)
Dim i As Integer
'获取C:盘根目录下的文件夹
Dim str() As String = IO.Directory.GetDirectorIEs("F:\PC_Code")
For i = 0 To str.GetUpperBound(0)
'调用遍历过程
AddDirectory("F:\PC_Code:",node)
Next
node = nothing
IDir = nothing
End Sub
Function Getfiles(ByVal MyDir As String) As IEnumerable(Of System.IO.fileInfo)
Dim Coll As System.Collections.ObjectModel.ReadonlyCollection(Of String)
Coll = My.Computer.fileSystem.Getfiles("F:\PC_Code\1")
Dim filename As String
For Each filename In Coll
Dim node As New TreeNode
node.ImageIndex = 1
Dim arr As String() = filename.Split("\")
node.Text = arr(arr.Length - 1)
TreeVIEw1.Nodes.Add(node)
Next
If (Not System.IO.Directory.Exists(MyDir)) Then
Throw New System.IO.DirectoryNotFoundException()
End If
Dim Myfilenames As String()
Dim Myfiles As List(Of System.IO.fileInfo) = New List(Of System.IO.fileInfo)()
Myfilenames = System.IO.Directory.Getfiles(MyDir)
For Each Myname As String In Myfilenames
Myfiles.Add(New System.IO.fileInfo(Myname))
Next
Return Myfiles
End Function
Private Sub button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button2.Click
Dim MyDir As String = "F:\PC_Code\1"
Dim List As List(Of String) = New List(Of String)
Dim Myfiles = Getfiles(MyDir)
Dim MyStartDate As DateTime = Me.dateTimePicker1.Value
Dim MyEndDate As DateTime = Me.dateTimePicker2.Value
End Sub End Class
总结以上是内存溢出为你收集整理的VB.net TreeView 读取系统文件名全部内容,希望文章能够帮你解决VB.net TreeView 读取系统文件名所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)