Python: getting file modification time with higher resolution than second

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

Is this the highest resolution for a Windows or OSX file system, or is there a way to get a higher resolution by file time?

+4
source share
3 answers

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

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

Including, for example, Windows , the FILETIME structure used to represent file time uses a resolution of 100 ns. I would expect Python to β€œrecognize” this and give you the best resolution. Is it possible that you are using files in the FAT file system?

+4
source

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

+4
source

As described in the Python os module , this is a portable interface for OS-specific functionality. Depending on which platform you are running on, you will get different behavior.

In particular, the modification time returned by stat calls depends on the file system in which the files are located. For example, for entries in the FAT file system, the maximum resolution for the modification time is 2 seconds. Other file systems will have different permissions.

+1
source

Source: https://habr.com/ru/post/1285652/


All Articles