For example =>
Dim files = Directory.GetFiles("C:\path", ".", SearchOption.AllDirectories).Where(Function(f) f.EndsWith(".mp3") OrElse f.EndsWith(".jpg")).ToArray
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
var files = Directory.GetFiles("C:\path", ".", SearchOption.AllDirectories)
.Where(s => s.EndsWith(".mp3") || s.EndsWith(".jpg"));
How to convert to VB.NET?
For example =>
Dim files = Directory.GetFiles("C:\path", ".", SearchOption.AllDirectories).Where(Function(f) f.EndsWith(".mp3") OrElse f.EndsWith(".jpg")).ToArray
The following may not be for you as it's really for large folder structures.
If by chance you have a large folder structure you may consider a different approach that keep the UI responsive. In the screenshot below the code in this case uses recursion to find *.png, *.exe (I used different extensions from you simply because I don't have any mp3 or jpg files). The code presented has plenty of room for customization.
Coded in VS2019
Front-end project, back-end project.
Shows what was searched folder-wise
Shows results (you could add the path on, in the code the path is available)
You can use C# to VB.NET Converter for free for output up to 100 lines per file. There is a snippet option that can convert snippets such as you are asking about.
There's the function below
1. Dim wildcards As String() = {"*.mp3", "*.jpg"}
Dim ListFiles As List(Of String) = FileIO.FileSystem.GetFiles("G:\Music", FileIO.SearchOption.SearchAllSubDirectories, wildcards).ToList
But the result is different with
I used two functions to get my music folder, NO1 return 617, NO2 return 593, can you test on your side? thank you.
The C# code below is easy for more file types.
var allowedExtensions = new [] {".doc", ".docx", ".pdf", ".ppt", ".pptx", ".xls", ".xslx"};
var files = Directory
.GetFiles(folder)
.Where(file => allowedExtensions.Any(file.ToLower().EndsWith))
.ToList();
How to convert to VB.NET?