假设要搜索的文件夹是:"C:\Directory\"
Dim MyDir As String = "C:\Directory\"
Dim TxtLine12 As String = ""
Dim TxtLine13 As String = ""
'在指定的文件夹"C:\Directory\"中搜索所有的文本文件
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir)
'搜索到一个TXT文件
If UCase(Microsoft.VisualBasic.Right(MyFile, 3)) = "TXT" Then
'显示文件名
MsgBox(MyFile)
'以读的方式打开该文件
Dim r As New System.IO.StreamReader(MyFile, System.Text.Encoding.Default) '用StreamReader打开文本文件准备读
Dim Fline As String = ""
Dim i As Integer = 0
For i = 1 To 11
Fline = r.ReadLine '从打开的文件中读取1行文本
Next
TxtLine12 = r.ReadLine '从打开的文件中读取第12行文本
TxtLine13 = r.ReadLine '从打开的文件中读取第13行文本
r.Close() '关闭对象
'显示读取的信息
MsgBox(TxtLine12)
MsgBox(TxtLine13)
End If
Next