-
-
Save clingerman/e48ab5e737a8ab77abff49c3c2235468 to your computer and use it in GitHub Desktop.
combine multiple xml files into one (Python 2.7)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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