Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Getting file modification times with greater resolution than a second

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?

like image 435
David Sykes Avatar asked Jun 03 '09 07:06

David Sykes


2 Answers

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

like image 193
Miles Avatar answered Oct 14 '22 15:10

Miles


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?

like image 31
unwind Avatar answered Oct 14 '22 15:10

unwind