import sys, os path = "static/files/" for path, subdirs, files in os.walk(path): for name in files: if name.endswith('html'): file = os.path.join(path, name) total = open("allhtml.txt", "a") with open(file, 'r') as f: print(file) # print(f.readlines()) content = f.read() print(content) total.write(content) total.close()