Below is my code, what I am trying to achieve is walking through the OS generating a MD5 hash of every file the code is functional, however, I receive the error in the title "ioerror errno 13 permission denied: 'C:\pagefile.sys'" when I try to run the file from C:\ is there a way i can run this as an admin? Even when I run cmd as an admin that does not work, thank you in advance.
import os, hashlib
current_dir = os.getcwd()
for root,dirs,files in os.walk(current_dir):
for f in files:
current_file = os.path.join(root,f)
H = hashlib.md5()
with open(current_file) as FIN:
H.update(FIN.read())
with open("gethashes.txt", "a") as myfile:
myfile.write(current_file),myfile.write(", "),myfile.write(H.hexdigest()),myfile.write("\n")
print current_file, H.hexdigest()
As mentioned in error - Permission denied - since file need to be read for getting md5 of its content. There will be always a case when we don't have read permission .
Please let me know if it is useful.