Reputation: 49
I am trying to get the last access file using Python. Even after accessing the files using vi/sublime or any other editor, the access time of the file does not get updated.
I have tried to use the function os.stat(full_path).st_atime
but of no use. It throws out the correct result only if the file is modified.
Just following up on the link alternative to getatime to find last file access in python
Upvotes: 2
Views: 1522
Reputation: 11
Find last creation file:
def findlatestfile(folder):
list_of_files = glob.glob(folder+'/*')
latest_file = max(list_of_files, key=os.path.getctime)
return latest_file
Upvotes: 0
Reputation: 10553
You should check this way:
(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:
To check creation&modification dates
print "last modified: %s" % time.ctime(os.path.getmtime(file))
print "created: %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)
Upvotes: 2