利用python計(jì)算windows全盤文件md5值的腳本
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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Pytorch從0實(shí)現(xiàn)Transformer的實(shí)踐
本文主要介紹了Pytorch從0實(shí)現(xiàn)Transformer的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05python 爬蟲 實(shí)現(xiàn)增量去重和定時(shí)爬取實(shí)例
今天小編就為大家分享一篇python 爬蟲 實(shí)現(xiàn)增量去重和定時(shí)爬取實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02linux系統(tǒng)下pip升級(jí)報(bào)錯(cuò)的解決方法
這篇文章主要給大家介紹了關(guān)于linux系統(tǒng)下pip升級(jí)報(bào)錯(cuò)的解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01python實(shí)現(xiàn)WebSocket服務(wù)端過程解析
這篇文章主要介紹了python實(shí)現(xiàn)WebSocket服務(wù)端過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10Python+selenium實(shí)現(xiàn)瀏覽器基本操作詳解
這篇文章主要為大家詳細(xì)介紹了如何通過python腳本實(shí)現(xiàn)瀏覽器的一些基本操作,如:瀏覽器的前進(jìn)后退、頁面刷新等,感興趣的可以學(xué)習(xí)一下2022-06-06在python3中實(shí)現(xiàn)查找數(shù)組中最接近與某值的元素操作
今天小編就為大家分享一篇在python3中實(shí)現(xiàn)查找數(shù)組中最接近與某值的元素操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02Python一個(gè)簡(jiǎn)單的通信程序(客戶端 服務(wù)器)
今天小編就為大家分享一篇關(guān)于Python一個(gè)簡(jiǎn)單的通信程序(客戶端 服務(wù)器),小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03Python實(shí)現(xiàn)二叉搜索樹BST的方法示例
這篇文章主要介紹了Python實(shí)現(xiàn)二叉搜索樹BST的方法示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07