How to order by descending

Hi,
I’m trying to add a orderbydescending function to the following line of code:

NewFiles = Directory.GetFiles(“C:.…”, “*.xlsm”).where(function(a) file.GetLastWriteTime(a).Year = Now.Year)
I tried a couple variations none of them works.

thanks

Hi @B.D,

Try following linQ code,

Directory.GetFiles(“C:....”,“.xlsm”).OrderByDescending(function(s) file.GetLastWriteTime(s)).where(function(s).GetLastWriteTime(s).Year = Now.Year) 
3 Likes

Hi,

If you want to orderbydescending by filename, the following might help you.

Directory.GetFiles("C...”, “*.xlsm”).OrderByDescending(function(r) r).where(function(a) file.GetLastWriteTime(a).Year = Now.Year)

Regards,

2 Likes

Hi Yoichi, I want it to order by last write time.

thanks samir I will try it.

Hi,

How about the following?

Directory.GetFiles("C:...”, “*.xlsm”).OrderByDescending(function(a) file.GetLastWriteTime(a)).where(function(a) file.GetLastWriteTime(a).Year = Now.Year)

Regards,

2 Likes

@B.D
Try previous linQ.
OR you can use assign like this

ArrVar = ArrVar.Reverse.toArray()

—> to simply reverse sequence of all array objects.

2 Likes

thank you it works. But when I itterate through the array the last item is ths

‘system.Linq.Enumerable+whereEnumerableterator’1[system.string]’

I don’t know why. What is the method to remove the last element from the array ?

@B.D

Assign
ArrVar = ArrVar.take(ArrVar.Count-1).toArray()

2 Likes

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