It's quite easy. See:
Dim dirinfo As DirectoryInfo = New DirectoryInfo("C:\users\Sonhospa\documents")
Dim pattern As String = "*"
Dim supportedExtensions As String() = {".xls", ".doc", ".xlsx", ".docx"}
Dim filelist = dirInfo.GetFiles(pattern) _
.Where(Function(file) supportedExtensions.Contains(Path.GetExtension(file.Extension).ToLower())) _
.Select(Function(file) New With _
{ _
.FileName = file.FullName, _
.Length = file.Length, _
.LastWriteTime = file.LastWriteTime _
}) _
.ToList()
Note #1: i've moved
Where
statement up, before
Select
Note #2: above code returns
List(of AnonymousType(Of String, Int64, DateTime))
If you would like to return a colection of specific type, please see:
How to: Return a LINQ Query Result as a Specific Type (Visual Basic) | Microsoft Docs[
^]
For example:
Public Class ShortFileInfo
Public Property FileName As String
Public Property Length As Long
Public Property LastWriteTime As DateTime
End Class
A query have to be changed this way:
.Select(Function(file) New ShortFileInfo() With _
{ _
.FileName = file.FullName, _
.Length = file.Length, _
.LastWriteTime = file.LastWriteTime _
}) _