I have a small program through which I am trying to read log files generated in a file location like below
Error_Suspects = ['Error', 'ERROR', 'Failed', 'Failure']
def detect_suspects(file_path, word_list):
with open(file_path) as LogFile:
Summary = {word: [] for word in word_list}
failure = ':'
for num, line in enumerate(LogFile, start=1):
for word in word_list:
if word in line:
failure += '<li>' + line + '</li>'
return failure
Result = detect_suspects(r'C:\scripts\Log.txt', Error_Suspects)
now the issue is this was good until I have only one single file. But now the files are generated at a certain interval with the timestamp as below.
I want to modify the above program in such a way so that it should always check the file with the latest time stamp. Also, I want to loop this program to run every 5 mins to check for the latest file. If new file doesn't arrive within 5 min it should not read the old one (which is already been read)