大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
'通过过System.IO.DirectoryInfo对象可以查阅目录信息,下面是遍历一个文件夹下所有层次的子文件夹,如果只检查下一层目录就更简单了。
站在用户的角度思考问题,与客户深入沟通,找到开州网站设计与开州网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、网站制作、企业官网、英文网站、手机端网站、网站推广、申请域名、虚拟空间、企业邮箱。业务覆盖开州地区。
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.net没几条方法可用。
建一个ImageList控件,右击,属性,在“图像”里插入图片(你的1.gif),看好他们的索引(Index,默认是1)。然后,代码如下。 ============ Private Sub Command1_Click() TreeView1.ImageList = ImageList1 '关联Treeview1与Imagelist1 TreeView1.LineStyle = tvwRootLines Dim nodX As Node TreeView1.Nodes.Add , , "a1", "teachername" Set nodX = TreeView1.Nodes.Add("a1", tvwChild, , "教师姓名", 1) '这个1的意思是刚才设置的图片在ImageList里的索引 End Sub
步骤如下:
窗体上添加2个列表框,一个按钮:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
'搜索并显示子文件夹
ListBox1.Items.Clear()
For Each MySubDir As String In System.IO.Directory.GetDirectories(MyDir)
ListBox1.Items.Add(MySubDir)
Next
'搜索并显示文件
ListBox2.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir)
ListBox2.Items.Add(MyFile)
Next
End Sub
End Class
vb.net:
Dim path = System.IO.Directory.GetFiles("D:\Log\abc", "*.txt", SearchOption.AllDirectories):搜索该路径下的所有txt类型的目录及子目录
path.AddRange(path)
Dim _RecordInfo As String
Dim _Reader As StreamReader
_Reader = New StreamReader(file, System.Text.Encoding.Default):'以Default编码的形式读取file文件(文件写入的编码要与读取的编码一致)