利用python計算windows全盤文件md5值的腳本
更新時間:2019年07月27日 11:16:35 作者:bainianminguo
這篇文章主要介紹了利用python計算windows全盤文件md5值的腳本,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
import hashlib
import os
import time
import configparser
import uuid
def test_file_md5(file_path):
test = hashlib.md5()
if os.path.isfile(file_path):
with open(file_path, "rb") as f:
while True:
data = f.read(8096)
if not data:
break
else:
test.update(data)
ret = test.hexdigest()
config = configparser.ConfigParser()
config.read("E:/python/pycharm/再開次開始/前端/test_md5.ini",encoding="utf-8")
if config.has_section(os.path.basename(file_path)):
new_section_name = str(os.path.basename(file_path)) + ":" + str(uuid.uuid4())
config[new_section_name] = {"文件路徑":os.path.dirname(file_path),
"md5值":ret}
else:
config[os.path.basename(file_path)] = {"文件路徑": os.path.dirname(file_path),
"md5值": ret}
config.write(open("E:/python/pycharm/再開次開始/前端/test_md5.ini","w",encoding="utf-8"))
def test_dir_md5(file_path):
test_abs_path = os.path.abspath(file_path)
# print(test_abs_path)
os.chdir(test_abs_path)
for file in os.listdir(os.getcwd()):
if os.path.isfile(file):
test_file_md5(os.path.abspath(file))
elif os.path.isdir(file):
test_dir_md5(os.path.abspath(file))
else:
pass
# return True
if __name__ == '__main__':
began_path = os.getcwd()
test_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(began_path))))
os.chdir(test_path)
print(os.listdir())
for test_file in os.listdir():
os.chdir(test_path)
if os.path.abspath(test_file).startswith("E:\\$"):
continue
else:
if os.path.isfile(test_file):
# print("yyyyy")
test_file_md5(os.path.abspath(test_file))
elif os.path.isdir(test_file):
# print("hahah")
test_dir_md5(os.path.abspath(test_file))
# print(os.path.abspath(test_file))
else:
pass
結(jié)果如下

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
Pytorch從0實現(xiàn)Transformer的實踐
本文主要介紹了Pytorch從0實現(xiàn)Transformer的實踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
python實現(xiàn)WebSocket服務(wù)端過程解析
這篇文章主要介紹了python實現(xiàn)WebSocket服務(wù)端過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-10-10
Python+selenium實現(xiàn)瀏覽器基本操作詳解
這篇文章主要為大家詳細(xì)介紹了如何通過python腳本實現(xiàn)瀏覽器的一些基本操作,如:瀏覽器的前進(jìn)后退、頁面刷新等,感興趣的可以學(xué)習(xí)一下2022-06-06
在python3中實現(xiàn)查找數(shù)組中最接近與某值的元素操作
今天小編就為大家分享一篇在python3中實現(xiàn)查找數(shù)組中最接近與某值的元素操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02

