Python get last reading time of a file -


this question has answer here:

i'm looking solution time file read @ last. file not modified or created opened in reading mode. works writing in file. if open file in read mode, time not correct:

f = open('my_path/test.txt', 'r') f.close()  print time.ctime(os.stat('my_path/test.txt').st_mtime) 

any hints?

you looking @ wrong entry in stat structure. want use .st_atime value instead:

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

from os.stat() documentation:

  • st_atime - time of recent access,

note not systems update atime timestamp, see criticism of atime. of 2.6.30, linux kernels default use relatime setting, atime values updated if on 24 hours old. can alter setting strictatime option in fstab.

windows vista disabled updates atime, can re-enable them.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -