Skip to content

Instantly share code, notes, and snippets.

@Shivam60
Created February 20, 2019 21:53
Show Gist options
  • Save Shivam60/78db838293425263c7b88f444556a7ec to your computer and use it in GitHub Desktop.
Save Shivam60/78db838293425263c7b88f444556a7ec to your computer and use it in GitHub Desktop.
'''
This code finds the md5 sum of all files present in a folder.
It assumes the path is valid.
'''
import os
import hashlib
path=r"I:\shivam\big_dataset"
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def FindMd5SumOfAllFilesPresent(path):
os.chdir(path)
print("The File Names With MD5 Sum are. ")
for files in os.listdir():
print(str(files),md5(files))
FindMd5SumOfAllFilesPresent(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment