String search from multiple files

This commit is contained in:
2024-05-10 22:55:57 +03:00
parent 974c7210fa
commit c959f71bdf
2 changed files with 38 additions and 1 deletions

33
findstring.py Normal file
View File

@@ -0,0 +1,33 @@
import os
text = input("input text : ")
path = input("path : ")
# os.chdir(path)
def getfiles(path):
f = 0
os.chdir(path)
files = os.listdir()
# print(files)
for file_name in files:
abs_path = os.path.abspath(file_name)
if os.path.isdir(abs_path):
getfiles(abs_path)
if os.path.isfile(abs_path):
f = open(file_name, "r")
if text in f.read():
f = 1
print(text + " found in ")
final_path = os.path.abspath(file_name)
print(final_path)
return True
if f == 1:
print(text + " not found! ")
return False
getfiles(path)