Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

You are looking for FileDate.

share|improve this answer
    
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). –  jmlopez May 19 '12 at 0:36
    
@jmlopez I started my search with FileNames which had a link to File Operations, and under File Properties was FileDate. –  rcollyer May 19 '12 at 0:38
add comment

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"
*)
share|improve this answer
    
What my answer should have looked like, +1. –  rcollyer May 19 '12 at 3:11
1  
@rcollyer yet another example of why we need collaborative answers. –  Mr.Wizard May 19 '12 at 9:52
    
@Mr.Wizard, I think the collaborative answers should be implemented. Is someone working on this? –  jmlopez May 19 '12 at 17:57
    
@Mr.Wizard they do exist, in a way: community-wiki. But, not in the sense your thinking of. –  rcollyer May 19 '12 at 21:26
    
@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. –  Mr.Wizard May 19 '12 at 22:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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