-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecent_access_files.py
More file actions
29 lines (21 loc) · 924 Bytes
/
recent_access_files.py
File metadata and controls
29 lines (21 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import datetime
def get_file_access_time(file_path):
return os.path.getatime(file_path)
def get_recently_accessed_files(
directory_path,time_threshold=None):
recently_accessed_files =[]
for root, dirs, files in os.walk(directory_path):
for file in files:
file_path = os.path.join(root,file)
file_access_time = get_file_access_time(file_path)
return sorted(recently_accessed_files,key=lambda file_path:get_file_access_time(file_path),reverse=True)
def main():
directory_path = input(
"Enter the directory path to search:")
recently_accessed_files = get_recently_accessed_files(directory_path)
print("List of recently accessed files:")
for file_path in recently_accessed_files:
print(f"{file_path}")
if __name__ == "__main__":
main()