簡體   English   中英

在 python 中查找最后一個文件訪問

[英]Find last file access in python

我正在嘗試使用 Python 獲取最后一個訪問文件。 即使在使用 vi/sublime 或任何其他編輯器訪問文件后,文件的訪問時間也不會更新。 我曾嘗試使用 function os.stat(full_path).st_atime但沒有用。 只有當文件被修改時,它才會拋出正確的結果。

只需跟進 getatime 的鏈接替代方法,即可在 python 中找到最后一個文件訪問

您應該這樣檢查:

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

我建議您在os.stat()文檔中查看官方信息:

查看創建和修改日期

print "last modified: %s" % time.ctime(os.path.getmtime(file))
print "created: %s" % time.ctime(os.path.getctime(file))

要么

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

查找最后一個創建文件:

def findlatestfile(folder):
    list_of_files = glob.glob(folder+'/*') 
    latest_file = max(list_of_files, key=os.path.getctime)
    return latest_file

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM