0
我正在使用以下代码在我的计算机中搜索带有certian扩展名的文件。我目前正在搜索.eml文件。此代码列出找到的所有文件。 我需要输入10个最新文件的路径到我的列表框。我该怎么做?谢谢仅获取10个最新文件
Dim DriveLetter As String = "c:\" '"
Dim Ext As String = ".eml"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.SearchPath(DriveLetter)
End Sub
Sub SearchPath(ByVal Path As String)
Dim DirParent As New IO.DirectoryInfo(Path)
''# Me.AddResults("Searching: " & DirParent.FullName)
Dim ListFiles() As IO.FileInfo
Try
ListFiles = DirParent.GetFiles("*" & Ext)
For Each SingleFile In ListFiles
Me.AddResults("Found: " & SingleFile.FullName)
Application.DoEvents()
Next
Catch ex As Exception
''# Me.AddResults("GET FILES ERROR: " & ex.Message)
End Try
Try
Dim DirChildren() As IO.DirectoryInfo = DirParent.GetDirectories
For Each DirEnum In DirChildren
SearchPath(DirEnum.FullName)
Next
Catch ex As Exception
''# Me.AddResults("GET DIRS ERROR: " & ex.Message)
End Try
End Sub
Sub AddResults(ByVal ResultString As String)
lstFiles.Items.Add(ResultString)
Application.DoEvents()
End Sub
非常感谢。但我不知道LINQ。请修改我的代码应该如何使用。这将是一个很大的忙。谢谢 – 2010-09-22 09:37:49
@Tim:无论如何'ToList'都是多余的。其余的看起来不错。 – 2010-09-22 09:39:21
代码提供了以下错误 – 2010-09-22 09:57:37