Hi,
i am using following code to search my computer for files with certian extensions. I currenty searching for .eml files. This code lists all files found. I need to enter 10 most current files' path to my list box. How can I do it? Thanks
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