2

With Python, to get the creation date of a file, I usually do the following:

import os, time
f = 'myFile.txt'
fileStats = os.stat(f)
time.ctime(fileStats.st_birthtime)

Using PyPy 5.1.1 I just discovered that 'stat_result' object has no attribute 'st_birthtime' I have checked all the other attributes: posix.stat_result(st_mode=33188, st_ino=4410002, st_dev=16777218, st_nlink=1, st_uid=10825, st_gid=20, st_size=62782, _integer_atime=1466067213, _integer_mtime=1462951964, _integer_ctime=1462951965) and I was expecting _integer_ctime to give me the creation date of the file but, instead, it gives the last modification date (almost identical to _integer_mtime that is supposed to be the actual modification date...) rather than the creation date.

So, how do I get the creation date of a file using PyPy? Also, what exactly is _integer_ctime then?

alec_djinn
  • 10,104
  • 8
  • 46
  • 71
  • http://stackoverflow.com/a/237084/6194839 – Bryce Drew Jun 20 '16 at 16:08
  • No `st_birthtime` attribute on my CPython 2.7. It must be something OS-specific, for a OS different than Linux, or a 3.x feature. In this case please report a bug. – Armin Rigo Jun 20 '16 at 16:52
  • About `st_ctime` giving a strange answer, please compare it with CPython 2.7: if it gives a different answer on the same file, then it's also a bug, then please report it too :-) – Armin Rigo Jun 20 '16 at 16:55
  • CPython gives the same answer, that is the last modification date, not the creation date. About the OS, I am using OSX El Capitan. – alec_djinn Jun 21 '16 at 07:52
  • Reading the docs, indeed states that `st_ctime` is platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows) But also states: On other Unix systems (such as FreeBSD), the following attributes may be available (but may be only filled out if root tries to use them): ...`st_birthtime` - time of file creation. On OSX using Python2.7 I have `st_birthtime` but using PyPy no... – alec_djinn Jun 21 '16 at 08:01

0 Answers0