The Visual Basic My.Computer.FileSystem GetFiles method can be used to search for files with a specific extension in or below a specific directory:
Below is a function for that purpose:
Private Function GetFilePathList(ByVal specialDirectoryPath As String, ByVal fileExtension As String) _
As List(Of String)
' Instantiate a list of type String.
Dim filePathList As New List(Of String)
' Use the My.Computer.FileSystem GetFiles method to search for files with a specific file
' extension in or below a specific directory.
' Note the use of the FileIO.SearchOption SearchAllSubDirectories to request all directories
' below the specifified directory be searched too.
For Each filePath As String In My.Computer.FileSystem.GetFiles(specialDirectoryPath, _
FileIO.SearchOption.SearchAllSubDirectories, fileExtension)
filePathList.Add(filePath)
Next
Return filePathList
End Function
Here's an example show how to call the function above:
Dim fileList As List(Of String) = GetFilePathList(My.Computer.FileSystem.SpecialDirectories.MyPictures, "*.png")
Mike McIntyre's .Net Journal
getdotnetcode.com