FileNames retrieves a list of all files in a directory. But is there a way to order these files by their most recent modification time?

  • 5
    $\begingroup$ Try this: SortBy[FileNames["*", {Directory[]}], FileDate]. $\endgroup$ Commented Mar 27, 2020 at 22:00
  • $\begingroup$ @LeonidShifrin that would make a good answer (it works). $\endgroup$
    – C. E.
    Commented Mar 27, 2020 at 22:02
  • $\begingroup$ @C.E. Done as requested. $\endgroup$ Commented Mar 29, 2020 at 14:43

1 Answer 1


You need FileDate. It returns a DateObject, and is therefore directly suitable to be used in SortBy. For example:

 SortBy[FileNames["*", {Directory[]}], FileDate]

FileDate takes an optional second argument, which can specify types of changes one is interested in: "Access", "Change", "Creation", and "Modification", with the latter being the default (see documentation for more details).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.