Created
March 27, 2019 14:19
-
-
Save gustavorv86/e47e1b6c7ea136b4428bb02c6438c47a to your computer and use it in GitHub Desktop.
Python get MD5 of file
This file contains hidden or 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
#!/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