I have created 2 different .txt files in the directory of the script called
test.txt
and
test2.txt
and i have written
word
in each file but different lines. and got the following result after executing the script:
<_io.TextIOWrapper name=[b]'test.txt'[/b] mode='r' encoding='UTF-8'>
<_io.TextIOWrapper name=[b]'test2.txt'[/b] mode='r' encoding='UTF-8'>
I have used the following libs:
from os import listdir
from os.path import isfile, join
What I did was to create a list called
db = []
, then I have used
listdir('.')
to iterate trough each item in the current directory.
after that by using endswith method
if dir_.endswith('.txt'):
i have been able to only read the txt files.
and then last part was to read each file and see if it was containing the word
word
.
with open(dir_,'r') as file_: