views:

431

answers:

3

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?

+2  A: 

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?

unwind
The files were written on an OSX file system, and only showed greater resolution on Windows when modified on the Windows system
David Sykes
+1  A: 

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

Miles
+1  A: 

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.

bignose