I need to build a simple script in python3 that opens more files inside a directory and see if inside these files is a keyword.
All the files inside the directory are like this: "f*.formatoffile" (* stays for a casual number)
Example:
f9993546.txt
f10916138.txt
f6325802.txt
Obviusly i just need to open the txt files ones.
Thanks in advance!
Final script:
import os
Path = "path of files"
filelist = os.listdir(Path)
for x in filelist:
if x.endswith(".txt"):
try:
with open(Path + x, "r", encoding="ascii") as y:
for line in y:
if "firefox" in line:
print ("Found in %s !" % (x))
except:
pass
glob.glob.