利用python计算windows全盘文件md5值的脚本
2018-02-28 19:21
525 查看
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
结果如下
相关文章推荐
- Windows运行python脚本文件
- 利用python爬虫大量基金股票的净值写入到csv文件中方便做其他计算
- Python : 计算大文件MD5值
- 如何利用openssl来计算一个文件的MD5值?
- Python脚本 —Windows下文件备份
- windows 编译 python脚本为exe文件
- Python小脚本:计算两个文件内容的相似率
- Python计算文件MD5值
- Windows下Python3实现C++多文件编译脚本(没有Make怎么办)
- 【转】让Souce Insight支持多种语言的语法高亮:Python,Ruby,ARM汇编,windows脚本文件(bat/batch),PPC,SQL,TCL,Delphi等
- Python -- 计算文件的md5值
- 利用脚本修复WINDOWS引导文件丢失
- Python利用pandas计算多个CSV文件数据值的实例
- 利用windows脚本实现Oracle数据库定时导出文件
- 用python计算文件的md5值
- 利用python fabric模块写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 在Windows、Linux下,分别利用BAT批处理文件和Shell脚本,生成类似“20150605_111327.txt”命名的文件
- 在Windows系统中,如何python脚本实现分割合并大二进制文件,方便上传
- 如何利用Python2.7、py2exe、PyInstaller-2.1将*.py打包成*.exe,再利用Inno Setup Compiler封装成windows安装文件
- Windows平台使用PyInstaller将Python脚本打包成可执行文件