4
$\begingroup$

Is there a command in Mathematica to check the date when a file was last modified? Suppose I have two notebooks: File1.nb and File2.nb, I need a way to find out which notebook is older. If no such command exists is there a way to do this in Mathematica regardless of the operating system we are working on?

$\endgroup$

2 Answers 2

10
$\begingroup$

You are looking for FileDate.

$\endgroup$
2
  • $\begingroup$ lol, I feel dumb now. I had been looking all over google for it but forgot to put it in the documentation center. What is more embarrassing, is that the tag for the question is all I had to put in the documentation center to find the answer (It took me a while to think of the tag too). $\endgroup$
    – jmlopez
    May 19, 2012 at 0:36
  • $\begingroup$ @jmlopez I started my search with FileNames which had a link to File Operations, and under File Properties was FileDate. $\endgroup$
    – rcollyer
    May 19, 2012 at 0:38
12
$\begingroup$

Here are some commands I ran on my machine to generate a few files, and give them some history:

touch foo1 foo2 foo3 foo4
touch foo3
cat foo2

Here are the files:

files = FileNames["foo*"]

(*
==> {"foo1", "foo2", "foo3", "foo4"}
*)

The most recently changed file:

SortBy[files, FileDate] // Last

(*
==> "foo3"
*)

The newest file:

SortBy[files, FileDate[#, "Creation"] &] // Last

(*
==> "foo4"
*)

The most recent file that was looked at:

SortBy[files, FileDate[#, "Access"] &] // Last

(*
==> "foo2"
*)
$\endgroup$
5
  • $\begingroup$ What my answer should have looked like, +1. $\endgroup$
    – rcollyer
    May 19, 2012 at 3:11
  • 1
    $\begingroup$ @rcollyer yet another example of why we need collaborative answers. $\endgroup$
    – Mr.Wizard
    May 19, 2012 at 9:52
  • $\begingroup$ @Mr.Wizard, I think the collaborative answers should be implemented. Is someone working on this? $\endgroup$
    – jmlopez
    May 19, 2012 at 17:57
  • $\begingroup$ @Mr.Wizard they do exist, in a way: community-wiki. But, not in the sense your thinking of. $\endgroup$
    – rcollyer
    May 19, 2012 at 21:26
  • $\begingroup$ @jmlopez as far as I know: not at this time. I am hoping to built interest in this possible feature, at which time the devs may consider it. $\endgroup$
    – Mr.Wizard
    May 19, 2012 at 22:48

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.