Skip to content

Instantly share code, notes, and snippets.

@dagg
Created October 16, 2015 00:12
Show Gist options
  • Save dagg/be3e0b1de491fafb44d5 to your computer and use it in GitHub Desktop.
Save dagg/be3e0b1de491fafb44d5 to your computer and use it in GitHub Desktop.
md5sum of a file in python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import hashlib
def generate_file_md5(rootdir, filename, blocksize=2**20):
m = hashlib.md5()
with open( os.path.join(rootdir, filename) , "rb" ) as f:
while True:
buf = f.read(blocksize)
if not buf:
break
m.update( buf )
return m.hexdigest()
def main():
dirr = str(sys.argv[1])
file = str(sys.argv[2])
print generate_file_md5(dirr, file)
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment