Skip to content

Instantly share code, notes, and snippets.

@vivekraj59
Forked from DominicBM/combine.py
Created April 17, 2019 03:36
Show Gist options
  • Save vivekraj59/305dbbdb47bd435449094e170a41449b to your computer and use it in GitHub Desktop.
Save vivekraj59/305dbbdb47bd435449094e170a41449b to your computer and use it in GitHub Desktop.
combine multiple xml files into one (Python 2.7)
import os, re
file = 'm384-import-11.xml'
filenames = ['M384_0201_output.xml','M384_0202_output.xml','M384_0203_output.xml','M384_0204_output.xml','M384_0205_output.xml','M384_0206_output.xml','M384_0207_output.xml','M384_0208_output.xml','M384_0209_output.xml','M384_0210_output.xml','M384_0211_output.xml','M384_0212_output.xml','M384_0213_output.xml','M384_0214_output.xml','M384_0215_output.xml','M384_0216_output.xml','M384_0217_output.xml','M384_0218_output.xml','M384_0219_output.xml','M384_0220_output.xml']
counter = 2
outputfile = file
for fname in filenames:
in_size = (os.stat(fname).st_size / 1000000)
try:
out_size = (os.stat(file).st_size / 1000000)
except OSError:
out_size = 0
if (in_size + out_size) > 75:
file = re.split('\.', outputfile)[0] + '_' + str(counter) + '.xml'
counter = counter + 1
with open(file, 'a') as outfile:
with open(fname) as infile:
for line in infile:
outfile.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment