I am looking for some help performing actions on a set of files in two different directories using Python.
I am attempting to:
Search two different directories
Find the 15 last modified files (comparing files in both directories)
Read all 15 recently modified files line by line
I can accomplish reading through one file directory using glob. However, I cannot specify multiple directories. Is there another way I can accomplish this?
Below is my code which accomplishes grabbing the latest 15 files in dir1 but not dir2.
dir1 = glob.iglob("/dir1/data_log.*")
dir2 = glob.iglob("/dir2/message_log.*")
latest=heapq.nlargest(10, dir1, key=os.path.getmtime)
for fn in latest:
with open(fn) as f:
for line in f:
print(line)