import os from pathlib import Path import sys foldername = sys.argv[1] """ this script gives the text and tokens it could have all been one script but yeah the foldername is passed and an argument when calling the script """ header = ['text'] songsfile = open(foldername+'.txt', 'w', encoding='UTF8') for _,_, files in os.walk(foldername): for filename in files: print(filename) textsfile = open(Path(foldername, filename)) texts = textsfile.read() texts = texts.split('*'*50) texts = texts[1:] for text in texts: text_with_tokens = f"{text}\n" #print(text_with_tokens) songsfile.write(text_with_tokens)