Using Directory.GetFiles() WITH multiple extensions AND sort order
-
Hi, I have to get a directory file list, filtered on multiple extensions...and sorted! I use this, which is the fastest way I've found to get dir content filtered on multiple extensions:
Dim ext As String() = {"*.jpg", "*.bmp","*png"}
Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray
Array.Sort(files)and then use an array sort. I was wondering (and this is my question ;)) if there would be a way to do the sorting IN the same main line? A kind of:
Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)[B].Order By Name[/B]).ToArray
and, if yes, if I would gain speed doing this instead of sorting the array at the end (but I would do my test and report..as soon as I get a solution!!)? Thanks for your help!!
-
Hi, I have to get a directory file list, filtered on multiple extensions...and sorted! I use this, which is the fastest way I've found to get dir content filtered on multiple extensions:
Dim ext As String() = {"*.jpg", "*.bmp","*png"}
Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray
Array.Sort(files)and then use an array sort. I was wondering (and this is my question ;)) if there would be a way to do the sorting IN the same main line? A kind of:
Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)[B].Order By Name[/B]).ToArray
and, if yes, if I would gain speed doing this instead of sorting the array at the end (but I would do my test and report..as soon as I get a solution!!)? Thanks for your help!!
Jayme65 wrote:
if there would be a way to do the sorting IN the same main line? A kind of:
You can combine methods on a line, but that makes it a compound statement; it still execute a statement at a time. Getting a list and sorting are two distinctly different things.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Hi, I have to get a directory file list, filtered on multiple extensions...and sorted! I use this, which is the fastest way I've found to get dir content filtered on multiple extensions:
Dim ext As String() = {"*.jpg", "*.bmp","*png"}
Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray
Array.Sort(files)and then use an array sort. I was wondering (and this is my question ;)) if there would be a way to do the sorting IN the same main line? A kind of:
Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)[B].Order By Name[/B]).ToArray
and, if yes, if I would gain speed doing this instead of sorting the array at the end (but I would do my test and report..as soon as I get a solution!!)? Thanks for your help!!
Jayme65 wrote:
ext.SelectMany(Function(f) Directory.GetFiles(romPath, f))
This part gets the list three times, and filters it three times. Next, you turn it into an array, and sort that. It'd (probably) be faster to get the list once and filter it. Since
GetFiles
already returns an array, there's no need to convert it.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]