Python:以较高的分辨率获取文件修改时间 [英] Python: Getting file modification times with greater resolution than a second

查看:162
本文介绍了Python:以较高的分辨率获取文件修改时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

os.path.getmtime() os.stat()似乎仅在整秒内返回值。

在Windows或OSX文件系统上,这是最高的分辨率吗?还是有办法获得更高的文件时间分辨率?

解决方案

os.stat()的文档有一个注释:


$ b $的确切含义和分辨率b st_atime,st_mtime和st_ctime
成员取决于正在运行的
系统和文件系统。以
为例,在使用
FAT或FAT32文件系统的Windows系统上,st_mtime
的分辨率为2秒,而st_atime
只有1天的分辨率。有关
的详细信息,请参阅您的
操作系统文档。

例如 Windows ,用于表示文件时间的FILETIME结构使用100纳秒的分辨率。我希望Python知道这一点,并给你最好的解决方案。是否有可能在FAT文件系统上使用文件?


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?

解决方案

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?

这篇关于Python:以较高的分辨率获取文件修改时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆