Skip to content

Instantly share code, notes, and snippets.

@gustavorv86
Created March 27, 2019 14:19
Show Gist options
  • Save gustavorv86/e47e1b6c7ea136b4428bb02c6438c47a to your computer and use it in GitHub Desktop.
Save gustavorv86/e47e1b6c7ea136b4428bb02c6438c47a to your computer and use it in GitHub Desktop.
Python get MD5 of file
#!/usr/bin/env python
import hashlib
import os
import sys
def md5(path_file):
checksum = hashlib.md5()
fd = open(path_file, "r")
while True:
## Don't read the entire file at once...
data = fd.read(4096)
if len(data) == 0:
break
checksum.update(data)
return checksum.hexdigest()
def main(args):
for arg in args[1:]:
if os.path.isfile(arg):
print("{}: {}".format(arg, md5(arg)))
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment