└── String search from multiple files /String search from multiple files: -------------------------------------------------------------------------------- 1 | import os 2 | text = input("input text : ") 3 | path = input("path : ") 4 | # os.chdir(path) 5 | def getfiles(path): 6 | f = 0 7 | os.chdir(path) 8 | files = os.listdir() 9 | # print(files) 10 | for file_name in files: 11 | abs_path = os.path.abspath(file_name) 12 | if os.path.isdir(abs_path): 13 | getfiles(abs_path) 14 | if os.path.isfile(abs_path): 15 | f = open(file_name, "r") 16 | if text in f.read(): 17 | f = 1 18 | print(text + " found in ") 19 | final_path = os.path.abspath(file_name) 20 | print(final_path) 21 | return True 22 | if f == 1: 23 | print(text + " not found! ") 24 | return False 25 | 26 | getfiles(path) 27 | --------------------------------------------------------------------------------