How to Sort and get the files in Oder

Hi Team
i Have been using this method i m getting an error Called oderbyAccernding is not a member of the Array
i need to write the file paths in Oder
can someone help me to solve this issue

Directory.GetFiles(“New folder”).OrderByAscending

Thank you

new DirectoryInfo(YourDir).GetFiles().OrderBy(Function (x) x.Name).Select(Function (x) x.FullName).toArray

But check its failling on lexically ordering
grafik

if we can rely on this page number token pattern we can do:

(From fi In New DirectoryInfo("C:\_demo\DemoOrder").GetFiles()
Let pns = Regex.Match(fi.Name,"(?<=page)\d+").toString
Order By CInt(pns)
Select f=fi.FullName).toArray

if its coming from a splitting job, then maybe a sort on creation time can help

new DirectoryInfo(YourDir).GetFiles().OrderBy(Function (x) x.CreationTime).Select(Function (x) x.FullName).toArray

2 Likes

hi @ppr
i got an error call

Assign: Conversion from string “” to type ‘Integer’ is not valid.

looks like a file name without a number.

Please refer to the updated post elaborating on splitting job and ordering on creation time

Thank you @ppr
this worked

new DirectoryInfo(YourDir).GetFiles().OrderBy(Function (x) x.CreationTime).Select(Function (x) x.FullName).toArray

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.