I need to scan a directory for ex: C:\Users\Jack\Work
and search for a file name which has part text part numbers ex: Worklog_201810716_081.log
.
Could anyone please help me how can I use regexp in my code to search the file name specifically.
I have implemented the following hard code with the file name:
reg_lst = ["Error in log"]
for i, line in enumerate(open("C:\\Users\\Jack\Work\\Worklog_201810716_081.log")):
if any(compiled_reg.match(line) for compiled_reg in reg_lst):
print("Found on line %s" % (i+1))
print("Log msg: ", line)
This prints the message after Error in log
in the Worklog_201810716_081.log
file.
I need to write a generic code where I need to also scan other log files in the directory for a text search.