Dorr
Dorr

Reputation: 656

Python listing files/directories without updating last access time?

I wrote a simple code to check specific directory's last access time. Below code always prints the first execution time of this script. Another call of this script does not updating it. It always shows the same time Wed Dec 16 14:31:38 2020.

How can I get the actual last access time without modifying it from the script call?

import os
import time
import re

result = {}
for root, dirs, files in os.walk('/data/samples/'):
    if re.search(r'.*/[0-9a-f]{40}$', root):
        print(root, time.ctime(os.stat(root)).st_atime)
('/data/samples/a/b/c/4564564564564564564564564564564564564564', 'Wed Dec 16 14:31:38 2020')
('/data/samples/d/e/f/1231231231231231231231231231231231231231', 'Wed Dec 16 14:31:38 2020')
...

Upvotes: 0

Views: 146

Answers (1)

user12136024
user12136024

Reputation:

Maybe this can help:

https://superuser.com/questions/251263/the-last-access-date-is-not-changed-even-after-reading-the-file-on-windows-7

If you actually want the Last Access date updated the way it used to be, simply set the registry value to 0.

Upvotes: 0

Related Questions