vb.net如何遍历整个文件夹,后找出某一个文件?
解压密码:1299
10年积累的做网站、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有坊子免费网站建设让你可以放心的选择与我们合作。
假设路径为C:\abc
代码:
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim Files As ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles("C:\abc") Dim FileSize As Long, FileName As String = Nothing Dim oFileSize As Long For Each File As String In Files oFileSize = My.Computer.FileSystem.GetFileInfo(File).Length If oFileSize FileSize Then FileSize = oFileSize FileName = File End If Next Dim ListN As ListViewItem = New ListViewItem(My.Computer.FileSystem.GetName(FileName)) ListN.SubItems.Add(oFileSize " byte") ListN.SubItems.Add(My.Computer.FileSystem.GetFileInfo(FileName).Extension " 文件") ListN.SubItems.Add(FileName) ListView1.Items.Add(ListN) End SubEnd Class
详见源代码!!
vb.net 如何用通配符查找文件
步骤如下:
窗体上添加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遍历某个文件夹,并读取子目录中的指定文件
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文件(文件写入的编码要与读取的编码一致)
vb.net查找文件问题
思路:
1,使用ListBox1控件来存放搜索到的文件名,然后ListBox1.SelectedItem就可以返回选中项的文本;
2,利用获得的选中项文本(即文件与路径),使用打开文本文件的方法,读取内容显示在文本框里。
VB.NET遍历查找某个文件夹,并找出指定文件
解压密码:1299
假设路径为C:\abc
代码:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Files As ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles("C:\abc")
Dim FileSize As Long, FileName As String = Nothing
Dim oFileSize As Long
For Each File As String In Files
oFileSize = My.Computer.FileSystem.GetFileInfo(File).Length
If oFileSize FileSize Then
FileSize = oFileSize
FileName = File
End If
Next
Dim ListN As ListViewItem = New ListViewItem(My.Computer.FileSystem.GetName(FileName))
ListN.SubItems.Add(oFileSize " byte")
ListN.SubItems.Add(My.Computer.FileSystem.GetFileInfo(FileName).Extension " 文件")
ListN.SubItems.Add(FileName)
ListView1.Items.Add(ListN)
End Sub
End Class
详见源代码!!
本文名称:vb.net查找指定文件 vb 搜索文件
网页URL:http://scgulin.cn/article/dodseci.html