You can use the os.stat()
function to get the statistics of the directory and retrieve the st_atime
field, which represents the last time the directory was accessed. You can then convert the timestamp to a human-readable date format using the datetime
module.
Here's an example code snippet:
main.py266 chars9 lines
In this code, replace /path/to/directory/
with the actual path of the directory you want to check. The strftime()
method formats the datetime object as a string in the format YYYY-MM-DD HH:MM:SS
.
gistlibby LogSnag