利用python計(jì)算windows全盤文件md5值的腳本
更新時(shí)間:2019年07月27日 11:16:35 作者:bainianminguo
這篇文章主要介紹了利用python計(jì)算windows全盤文件md5值的腳本,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
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é)果如下

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
python入門課程第一講之安裝與優(yōu)缺點(diǎn)介紹
這篇文章主要介紹了python入門課程第一講之安裝與優(yōu)缺點(diǎn),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
python導(dǎo)出requirements.txt的幾種方法以及環(huán)境配置詳細(xì)流程
這篇文章主要給大家介紹了關(guān)于python導(dǎo)出requirements.txt的幾種方法以及環(huán)境配置詳細(xì)流程,requirements.txt 文件是一個(gè)文本文件,用于列出你的Python項(xiàng)目所依賴的軟件包及其版本,需要的朋友可以參考下2023-11-11
Python OpenCV 直方圖的計(jì)算與顯示的方法示例
這篇文章主要介紹了Python OpenCV 直方圖的計(jì)算與顯示的方法示例,主要介紹用NumPy和Matplotlib計(jì)算和繪制直方圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
Python中用于轉(zhuǎn)換字母為小寫的lower()方法使用簡(jiǎn)介
這篇文章主要介紹了Python中用于轉(zhuǎn)換字母為小寫的lower()方法使用,是Python學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-05-05
Python淺復(fù)制中對(duì)象生存周期實(shí)例分析
這篇文章主要介紹了Python淺復(fù)制中對(duì)象生存周期,結(jié)合實(shí)例形式分析了Python面向?qū)ο笾械臏\復(fù)制操作時(shí)對(duì)象的生命周期問題,需要的朋友可以參考下2018-04-04
python的pandas工具包,保存.csv文件時(shí)不要表頭的實(shí)例
今天小編小編就為大家分享一篇python的pandas工具包,保存.csv文件時(shí)不要表頭的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06
Python復(fù)制Excel中的行、列和單元格的操作代碼
在Excel中,復(fù)制行、列和單元格是日常工作中經(jīng)常需要進(jìn)行的操作,它可以幫助你快速調(diào)整數(shù)據(jù)布局、復(fù)制數(shù)據(jù)模板或進(jìn)行數(shù)據(jù)的批量處理,本文將詳細(xì)介紹如何使用Python將Excel中的行、列、或單元格范圍復(fù)制到指定位置,需要的朋友可以參考下2024-09-09

