Inconsistency in modified/created/accessed time on mac

Posted by Seth Johnson on Stack Overflow See other posts from Stack Overflow or by Seth Johnson
Published on 2010-03-19T18:28:14Z Indexed on 2010/03/19 18:31 UTC
Read the original article Hit count: 385

Filed under:
|
|
|

I'm having trouble using os.utime to correctly set the modification time on the mac (Mac OS X 10.6.2, running Python 2.6.1 from /usr/bin/python). It's not consistent with the touch utility, and it's not consistent with the properties displayed in the Finder's "get info" window.

Consider the following command sequence. The 'created' and 'modified' times in the plain text refer to the "get info" window attributes. As a reminder, os.utime takes arguments (filename, (atime, mtime)).

>>> import os
>>> open('tempfile','w').close()

'created' and 'modified' are both the current time.

>>> os.utime('tempfile', (1000000000, 1500000000) )

'created' is the current time, 'modified' is July 13, 2017.

>>> os.utime('tempfile', (1000000000, 1000000000) )

'created' and 'modified' are both September 8, 2001.

>>> os.path.getmtime('tempfile')
1000000000.0
>>> os.path.getctime('tempfile')
1269021939.0
>>> os.path.getatime('tempfile')
1269021951.0

...but the os.path.get?time and os.stat don't reflect it.

>>> os.utime('tempfile', (1500000000, 1000000000) )

'created' and 'modified' are still both September 8, 2001.

>>> os.utime('tempfile', (1500000000, 1500000000) )

'created' is September 8, 2001, 'modified' is July 13, 2017.

I'm not sure if this is a Python problem or a Mac stat problem. When I exit the Python shell and run

touch -a -t 200011221234 tempfile

neither the modification nor the creation times are changed, as expected. Then I run

touch -m -t 200011221234 tempfile

and both 'created' and 'modified' times are changed.

Does anyone have any idea what's going on? How do I change the modification and creation times consistently on the mac? (Yes, I am aware that on Unixy systems there is no "creation time.")

© Stack Overflow or respective owner

Related posts about python

Related posts about stat