I wrote a script in python a few years ago and havent since used python at all. The script joins text files together into a larger text file. The old text files were the same length and so i could indicate the lines i wanted to append onto the large text file. I now would like to make a larger text file from text files of varying lengths.

I realise this is a simple edit but everything i have tried has not worked. Can somebody point me in the right direction?

import osdir_path = '.'with open('output.txt', 'w') as outfile: for fname in os.listdir(dir_path): if os.path.splitext(fname)[1] == '.txt': with open(fname) as infile: for line in infile: outfile.write(line)