Skip to content

Instantly share code, notes, and snippets.

@aluzed
Last active April 17, 2020 10:51
Show Gist options
  • Save aluzed/92f51f5c1239d5f09eb1d59bb029fb30 to your computer and use it in GitHub Desktop.
Save aluzed/92f51f5c1239d5f09eb1d59bb029fb30 to your computer and use it in GitHub Desktop.
Python file merger
import sys, hashlib, argparse
parser = argparse.ArgumentParser(description='Merge files.')
parser.add_argument('files', type=argparse.FileType('r'), nargs='+')
args = parser.parse_args()
output_file = "output"
def concat(files):
with open(output_file, "ab") as out1:
for f in files:
with open(f.name, "rb") as fp:
out1.write(fp.read())
fp.close()
out1.close
print("merged into : " + output_file)
with open(output_file, "rb") as f:
md5 = hashlib.md5(f.read()).hexdigest()
print("MD5 : " + md5)
concat(args.files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment