7

os.path.getmtime() and os.stat() seem to return values in whole seconds only.

Is this the greatest resolution possible on either a Windows or OSX file system, or is there a way of getting greater resolution on file times?

4 Answers 4

6

HFS+ (used by OS X) has a date resolution of one second.

Sign up to request clarification or add additional context in comments.

2 Comments

The Wikipedia article you link to no longer says anything about the time resolution of HFS+. However, I found confirmation in John Siracusa's Lion review. arstechnica.com/apple/2011/07/mac-os-x-10-7/12
I think the only statement was ever the "Date resolution" in the infobox, which is still there. Not the best source... There's also the HFS+ technote, though that may be pretty outdated now—for instance, Mac OS X somehow has a way to store modification dates past 2040.
4

The documentation for os.stat() has a note that says:

The exact meaning and resolution of the st_atime, st_mtime, and st_ctime members depends on the operating system and the file system. For example, on Windows systems using the FAT or FAT32 file systems, st_mtime has 2-second resolution, and st_atime has only 1-day resolution. See your operating system documentation for details.

On for instance Windows, the FILETIME structure used to represent file times uses a 100-nanosecond resolution. I would expect Python to "know" this, and give you the best possible resolution. Is it possible that you're using files on a FAT filesystem?

1 Comment

The files were written on an OSX file system, and only showed greater resolution on Windows when modified on the Windows system
0

As documented in the Python os module, it is a portable interface to OS-specific functionality. Depending on what platform you're running on, you will get different behaviour.

Specifically, the modification time returned by stat calls is dependent on the filesystem where the files reside. For example, for entries in a FAT filesystem, the finest resolution for modification time is 2 seconds. Other filesystems will have different resolutions.

Comments

0

Python 3 os.stat() contains st_atime_ns, st_ctime_ns, st_mtime_ns properties with nano seconds resolution, depends on the time-structure saved by the file system. see: https://docs.python.org/3/library/os.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.