I'm trying to order a set of files base on its file name. Input is a directory with files like:
f0.vesperdp
f1.vesperdp
f2.vesperdp
....
f9.vesperdp
f10.vesperdp
f11.vesperdp
f12.vesperdp
I've built this LINQ query to sort them:
if (Directory.Exists(path))
{
var directoryInfo = new DirectoryInfo(path);
var files = from file in directoryInfo.EnumerateFiles()
.Where(f => f.Extension == PAGE_FILE_EXTENSION)
orderby file.Name.Substring(1, file.Name.Length - 1) ascending
select file.FullName;
return files.ToArray<string>();
}
But they are returning like
f0.vesperdp
f1.vesperdp
f10.vesperdp
....
f19.vesperdp
f2.vesperdp
f20.vesperdp
f21.vesperdp
I need them to be sorted using natural order (from 0 to n as f0,f1,f2...,f9,f10,f11
) how can fix my orderby filter to match this? Or if there's other way, how can I achieve that? Thanks in advance.