1
0

txtmerge.py 702 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. # usage: txtmerge.py <input_dir> <output_file_name>
  3. # does the exact opposite of txtsplit.py
  4. import os
  5. import sys
  6. import re
  7. import io
  8. assert len(sys.argv) == 3, "usage:\ntxtmerge.py <input_dir> <output_file_name>"
  9. idir = str(sys.argv[1])
  10. oname = str(sys.argv[2])
  11. ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
  12. for iname in sorted(os.listdir( idir )):
  13. ifile = io.open(os.path.join(idir,iname), 'rt', encoding='utf-8')
  14. text = ifile.read()
  15. # make sure there's a line at the end of file
  16. # (why wouldn't there be one? WINDOWS!
  17. if text[-1] != u'\n':
  18. text += u'\n\n'
  19. ofile.write(text)
  20. ifile.close()
  21. ofile.close()