How to get the oldest file created from the folder

Hi,

I am using the following code to get the latest file from a folder. Now, my requirement is to get the oldest file from the list, instead of the latest one. I don’t see the OrderByAscending function to use. Can someone help please?

Directory.GetFiles(“Path”,“ORCH"+".xlsx”).OrderByDescending(Function(d) New FileInfo(d).LastWriteTime).Where(Function(n) not path.GetFileName(n).Contains("~$"))(0)

@Krithi1

Just use OrderBy, it will order in ascending order

Directory.GetFiles("Path","ORCH"+".xlsx”).OrderBy(Function (d) New FileInfo(d).LastWriteTime).Where(Function (n) Not Path.GetFileName(n).Contains("~$")).First

Hi @Krithi1,

This looks like a duplicate post.
There are numerous solved threads (mostly by @prasath17) for similar questions :

Studio

StudioX


How to search?

Do use the search function (advanced search) in this forum. It is quite an accurate search.
image

Filtering to known forum members

2 Likes

Hi @Krithi1

  1. You will find show StudioX in Filters
    image
  2. Search for For each File
    image
  3. You can finf this activity and you can order by various options here
1 Like

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