在python中查找最后一次文件访问

在python中查找最后一次文件访问,python,Python,我正在尝试使用Python获取最后一个access文件。即使使用vi/sublime或任何其他编辑器访问文件,文件的访问时间也不会得到更新。 我尝试过使用函数os.stat(full_path).st_atime,但没有用。只有当文件被修改时,它才会抛出正确的结果 只需跟进链接您应该通过以下方式进行检查: (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file) print "last access:

我正在尝试使用Python获取最后一个access文件。即使使用vi/sublime或任何其他编辑器访问文件,文件的访问时间也不会得到更新。 我尝试过使用函数
os.stat(full_path).st_atime
,但没有用。只有当文件被修改时,它才会抛出正确的结果


只需跟进链接

您应该通过以下方式进行检查:

(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print "last access: %s" % time.ctime(atime)
我建议您查看以下官方信息:

检查创建和修改日期的步骤

(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print "Modification date: %s" % time.ctime(mtime)
print "Creation date: %s" % time.ctime(ctime)

atime
需要文件系统支持才能工作。看起来你的不知道你在用什么操作系统?我在用Linux(Ubuntu)。我能够在Linux中使用find命令找到解决方案:find/home/dir/-atime-10-print。但是,我想使用Python使用这个命令。有办法解决这个问题吗?感谢Liarez的回答,但是当我最近访问该文件时,atime参数没有更新,而是显示了旧的时间戳。os.stat()文档显示st_atime只有1天的分辨率。这是什么意思?您如何访问文件?使用vi或subl。并非所有命令都会修改文件的访问权限。如果要更改文件的访问时间,可以使用
touch-a filename
,然后如果选中
atime
,它将被更新。我不确定vi为什么不修改atimeMaybe这个问题可能对您有用:
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print "Modification date: %s" % time.ctime(mtime)
print "Creation date: %s" % time.ctime(ctime)