Hi
Late to the party, but here is my example (gleaned/modified from old google search sample), If time is critical then this example may help.
I incorporated @Sreeju Nair example to test differences. (all commented out)
The results seem to show this example to take about 60% of the time from first example. (for large data sets is significant)
Here is code for bot (need to rearrange stopwatch calls to try both. I just used my Visual studio Projects folder for testing purposes. File types can be added to 'filter' list as needed. I put results into a List(Of String) but could be anything.
Dim sw As New Stopwatch
Dim path As String = "C:\Users\lesha\Documents\Projects"
Dim filter As String = "*.vb,*.resx"
Dim res As New List(Of String)
Dim counter As Integer = 0
'Do
' Dim result As List(Of String) = Directory.EnumerateFiles(path, "*.vb", SearchOption.AllDirectories).Union(Directory.EnumerateFiles(path, "*.resx", SearchOption.AllDirectories)).ToList()
' res.AddRange(result)
' ' approx 625ms per cycle
' counter += 1
'Loop Until counter = 20
'Dim t As Long = sw.ElapsedMilliseconds
'eg 12480ms for the 20 cycles
' agreagated: average about 625ms per cycle on my system with 57560 results from 274000 total files
' about 12693ms for all cycles
'counter = 0
'sw.Restart()
sw.Start()
Do
res.AddRange(filter.Split(","c).AsParallel().SelectMany(Function(x) Directory.EnumerateFiles(path, x, SearchOption.AllDirectories)).OrderBy(Function(x) x).ToArray())
'ex. 377ms per cycle
counter += 1
Loop Until counter = 20
Dim t As Long = sw.ElapsedMilliseconds
'ex. 7530ms for the 20 cycles
' agreagated: average about 377ms per cycle on my system with 57560 results from 274000 total files
Stop