I am trying to get all files from a folder using GetFiles (path) and sort them by date/time.
New files are added in the folder and I am trying to extract the latest one.

Right now they are sorted alphabetically. Any ideas for the easiest way to do this?
Should be simple but I can’t figure it out.



Hi @Dorosp,

There might be an easier way to do this, but this is how I managed to get to it:

First add mscorlib as a dependency:



Then, navigate to the File class in the Node Browser:


And there, you should see the GetCreationTime and GetLastAccessTime nodes which will take in the string path for the file you want to check, and return the time value.

Hope that helps.

@ravazquez thanks a lot for your help and the detailed explanation.
I can see the GetCreationTime and GetLastAccess time and indeed I can now get the time value.

I assume now I have to somehow compare all the time values for all the files and see which one is the earliest. Any idea how to do this? I am still trying to wrap around my head how to use Loops.

Btw I am sure there must be an easier way… seems like we are re-inventing the wheel.


you can do this with an OrderBy node.

@tonfilm Thank you - I was trying to use OrderBy but I must be doing something wrong:

The GetCreationTime result inside the loop is wrong (1601?) - whereas outside the loop is correct.

Sorry I am new at Gamma, still learning. Any advice on how to resolve this - or atleast which OrderBy to use (there seems to be a lot of them).

Thank you.

just return the creation date as order key. the region basically asks you for every element what the order should be based on. so in this case the creation time, so connect that to the Result pin inside the region.

@Dorosp this works:


1 Like

Excellent, got it now.
Thank you @tgd and everyone else.