I would like to sort entries in a List(Of IO.FileInfo)
1. Filename number One.txt
10. Filename number 10.txt
11. Filename number 11.txt
12. Filename number 12.txt
...
19. Filename number 19.txt
2. Filename number Two.txt
20. Filename number 20.txt
21. Filename number 21.txt
...
as they appear 'naturally' sorted by the leading numbers in windows file explorer:
1./2./...10./11./12...19./20./21.
I use the following code to fill a List(Of IO.FileInfo)
Dim diStartDir As IO.DirectoryInfo = New IO.DirectoryInfo("C:\Temp")
Dim ListOfMatchingFiles As New List(Of IO.FileInfo)
For Each FileName In diStartDir.GetFiles("*.txt", IO.SearchOption.AllDirectories)
ListOfMatchingFiles.Add(Filename)
Next
ListOfMatchingFiles.Sort() '<-- naturally sort is the tricky part...
In the Visual Studio Designer, I don't get any error. If I debug this code, the last command .Sort() results in the error:
Fehler beim Vergleichen von zwei Elementen im Array.
An error occurred while comparing two elements.
I'm not able to get a working solution from the examples found with ICompare or LINQ.
Could you help me please with VB.NET code that allows to naturally sort my List(Of IO.FileInfo) by (file)name?