alec_djinn alec_djinn - 1 year ago 68
Python Question

File creation time do not match when using os.stat()

I need to access the date of creation of a file using Python.
As suggested in many posts, I am using

to get such information.
However, the result I get is different from the one I expect.
Here an example:

import os, time
f = 'untitled.ipynb' # Created 30 March 2016 at 15:45
fileStats = os.stat(f)

The result is :

'Mon May 2 16:04:27 2016'

Which is incorrect, if I look for it using "Get Info" (in OSX), I get:

"Created: 30 March 2016 at 15:45"

Does anyone experience the same error?

Do you have any solution to suggest?

Answer Source

accordint to the documentation at
since you are using OSX, what you need is st_birthtime instead of st_ctime

st_ctime - platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download