Jun-01-2021, 12:51 PM
Hello,
How do I check the time at which a file was opened last time ?
Thanks.
How do I check the time at which a file was opened last time ?
Thanks.
Check last time file was accessed
|
Jun-01-2021, 12:51 PM
Hello,
How do I check the time at which a file was opened last time ? Thanks.
Jun-01-2021, 01:10 PM
Try using
https://docs.python.org/3/library/os.html#os.stat Wrote:os.stat(path, *, dir_fd=None, follow_symlinks=True)to get https://docs.python.org/3/library/os.htm...t.st_atime Wrote:st_atime
Jun-01-2021, 03:12 PM
FYI: The same command is available if you are using pathlib objects see: https://docs.python.org/3/library/pathli....Path.stat
The command structure is the same (or very similar) as os.stat
Jun-01-2021, 04:42 PM
(This post was last modified: Jun-01-2021, 04:56 PM by Yoriz.
Edit Reason: Formatting
)
(Jun-01-2021, 01:10 PM)Yoriz Wrote: Try usingThanks. Not clear how to use. For example, how can I get last access time to all files, located in 'aaa/bbb/ccc/' ?
Jun-01-2021, 05:47 PM
Try this with a loop through your files
import pathlib import datetime def get_file_access_datetime(file_path): path = pathlib.Path(file_path) path_stat = path.stat() return datetime.datetime.fromtimestamp(path_stat.st_atime) |
|