import os import os.path as path data = [ ('661', r"C:\Users\xavier.gillard\Documents\ARKEY\Corpora\Vonnis\661_a\541_0009_000_00661_000_0_0344\txt"), ('691', r"C:\Users\xavier.gillard\Documents\ARKEY\Corpora\Vonnis\691\541_0009_000_00691_000_0_0374\txt"), ('875', r"C:\Users\xavier.gillard\Documents\ARKEY\Corpora\Vonnis\875\541_0009_000_00875_000_0_0236\txt") ] for (k, pth) in data: with open("vonnis/{}.txt".format(k), "w") as out: files = [ path.join(pth, e) for e in os.listdir(pth) ] files.sort() for f in files: with open(f) as input: print("###", file=out) text = input.read() print(text, file=out)