# Get most recent file(s) in a directory?

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?

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

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).