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?
1 Answer
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).
SortBy[FileNames["*", {Directory[]}], FileDate]
. $\endgroup$