I have a huge dir, with sub dirs and txt files.
I would like to search my dir/s recursevly for a specific string.
I would like to print the full path, and keyword if i find a match. For some reason I can't seem to get if keyword in line
to work. (I know that "williams" is in my files)
import os
search_path = "/home/lasse/Desktop/DB1"
file_type = ".txt"
keyword = "williams"
if not (search_path.endswith("/") or search_path.endswith("\\")):
search_path = search_path + "/"
if not os.path.exists(search_path):
search_path = "."
print("Path dosn't exists")
for folder, dirs, files in os.walk(search_path):
for file in files:
if file.endswith(file_type):
fullpath = os.path.join(folder, file)
with open(fullpath, 'r') as my_file:
for line in my_file:
print("test")
if keyword in line:
print(fullpath, line, keyword)
else:
print("Cant find keyword keyword")