Skip to content

Instantly share code, notes, and snippets.

@clingerman
Forked from DominicBM/combine.py
Last active August 8, 2022 21:52
Show Gist options
  • Save clingerman/e48ab5e737a8ab77abff49c3c2235468 to your computer and use it in GitHub Desktop.
Save clingerman/e48ab5e737a8ab77abff49c3c2235468 to your computer and use it in GitHub Desktop.
combine multiple xml files into one (Python 2.7)
import os, re, glob
file = 'm384-import-1.xml'
filenames = glob.glob("*.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