I need to sort file names as follows: 1.log, 2.log, 10.log
But when I use OrderBy(fn => fn) it will sort them as: 1.log, 10.log, 2.log
I obviously know that this could be done by writing another comparer, but is there a simpler way to change from lexicographical order to natural sort order?
Edit: the objective is to obtain the same ordering as when selecting "order by name" in Windows Explorer.
The simplest (not necessarily fastest/optimal) way would be IMHO to left-pad them all to some predefined maximum length with zeroes. I.e.
You should take one of these