简体   繁体   English

替代getatime在python中查找最后的文件访问

[英]alternative to getatime to find last file access in python

I am trying to see how many times some of the installed applications are being used on a system. 我正在尝试查看系统上已使用某些已安装应用程序的次数。

I used in my python script 我在我的python脚本中使用了

fileaccesstime=os.path.getatime(os.sep.join([dirpath, filename]))

Some of the applications dont seem to update atime even when accessed. 有些应用程序即使被访问似乎也不会随时更新。 For example, I used python and saw that atime did not change. 例如,我使用python并发现atime不变。

From Get last access time of the file? 获取文件的上次访问时间开始? it appears that atime might not get updated because it would call mmap. 似乎atime可能无法更新,因为它将调用mmap。

Does that mean I can never find the last access time. 这是否意味着我永远找不到最后的访问时间。 I am unsure how to proceed to find out the last access for some applications eg. 我不确定如何继续找出某些应用程序的最后访问权限,例如。 python 蟒蛇

You should check this way: 您应该这样检查:

import os, time
print time.ctime(os.stat('my_path/test.txt').st_atime)

OR 要么

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

I recommend you to check official info at os.stat() documentation : 我建议您在os.stat()文档中查看官方信息:

To check creation&modification dates 查看创建和修改日期

print "Modification Date: %s" % time.ctime(os.path.getmtime(file))
print "Creation Date: %s" % time.ctime(os.path.getctime(file))

OR 要么

(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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM