Descending Filename

Hello everyone,

I’ve some array data of filename to sort by descending.
Example of filename: A_1.xlsx, A_5.xlsx, A_2.xlsx
Expectation: A_1.xlsx, A_2.xlsx, A_5.xlsx

Can you help me?

Regards,
Brian H

HI @brian_satijadi

Try this

For getting descending array list
(From item In yourArray Select item Order By item Descending).ToArray

For Gettinng Ascending Array list
(From item In yourArray Select item Order By item Ascending).ToArray

Regards
Sudharsan

1 Like

Hello @brian_satijadi ,

You can use the below expression :
Output_Array = Input_Array.Orderby(function(x) x)

Thanks,
Rohith

currently not present within your sample but affected with the approach is following:
grafik

the function is sorting the files lexically so the A_2 is before the A_10

We would recommend to clear following:

  • are only filenames or fullFilePaths involved later within the production data?
  • is a lexically sorting expectedted or another sorting is needed e.g. number, Letter_Digit Pattern…

In general we will use the OrderByDescending method, but will adapt on the parts which we are providing for the ordering

Arr_Files.OrderByDescending(Function(F) CInt(Path.GetFileNameWithoutExtenstion(F).Split("_"c)(1))).Toarray