Assuming the file exists (using os.path.exists(filename)
to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference.
views:
738answers:
2
+6
A:
import os
filename = "/etc/fstab"
statbuf = os.stat(filename)
print "Modification time:",statbuf.st_mtime
Unfortunately I don't think Linux records the creation time. (At least it isn't available from os.stat).
Douglas Leeder
2008-12-17 16:38:08
Thank you. It appears that Linux doesn't store the file creation time. It seems like I should have known that. :)
Bill the Lizard
2008-12-17 17:09:42
+10
A:
>>> import os
>>> f = os.path.getmtime('test1.jpg')
>>> f
1223995325.0
since the beginning of (epoch)
Jack
2008-12-17 16:41:59
Thanks, this was helpful. This seems to be the more direct approach to my specific question, but the os.stat solution gives more information.
Bill the Lizard
2008-12-17 17:08:53
I didn't know that there was an explicit function for this. Live and learn I guess.
Douglas Leeder
2009-09-04 15:24:23
Me neither; time to replace `os.stat` with `os.path.getmtime` in my codebase...
Sridhar Ratnakumar
2009-09-04 22:23:33