4
$\begingroup$

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?

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

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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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