所以我有这个文件来浏览操作系统并使用python生成每个文件的哈希值,但是我希望它将哈希值输出到txt文件中。我尝试过使用:
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())
print current_file, H.hexdigest()
但我似乎无法让这一切工作我所取得的就是将最后一个哈希打印到文件中。任何建议都会受到欢迎!
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("/n"),myfile.write(" "),myfile.write(H.hexdigest()),myfile.write("%s\n")
print current_file, H.hexdigest()
编辑:道歉似乎我的解释不清楚,上面的代码打印MD5值很好但是我想要实现的是MD5s在打印时输出到文件中。
编辑2: 完整功能齐全的代码,适用于将来遇到困难的人(但目前我收到权限错误):
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]