import os



folder= input("Ce folder analizati : ")
files=os.listdir(folder)
# creating an empty list
lst = []

# number of elemetns as data_ro
n = int(input("Introduceti cate cuvinte cheie doriti sa cautati : "))
keys=[]
# iterating till the range
for i in range(0, n):
    koi = str(input())

    keys.append(koi)  # adding the element

for file in files:
    if '.txt' in file:
        
        f=open(folder+'\\'+file,encoding='iso-8859-2')
        data=f.read()

        f.close()
        visited = []
        for key in keys:
            if (key) in str(data) and key not in visited:
               visited += [key]               
               
        if len(visited)==len(keys):
            path = os.path.join(folder, 'result.txt')
            f2 = open(path, 'a', encoding='ISO-8859-2')


            f2.write(data)
            f2.write('\r')


            f2.close()
            flag=False

