Python’s os.path.getctime on the Mac (and under Unix in general) does not give the date when a file was created but “the time of the last change” (according to the docs at least). On the other hand in the Finder I can see the real file creation time so this information is kept by HFS+.
Do you have any suggestions on how to obtain the file creation time on the Mac in a Python program?
Use the
st_birthtimeproperty on the result of a call toos.stat()(orfstat/lstat).You can convert the integer result to a datetime object using
datetime.datetime.fromtimestamp().For some reason I don’t think this worked on Mac OS X when this answer was first written, but I could be mistaken, and it does work now, even with older versions of Python. The old answer is below for posterity.
Using
ctypesto access the system callstat64(works with Python 2.5+):Using
subprocessto call thestatutility: