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

结果如下

利用python计算windows全盘文件md5值的脚本的更多相关文章

  1. java计算过G文件md5 值计算

    package io.bigdata; import java.io.File; import java.io.FileInputStream; import java.io.IOException; ...

  2. windows查看文件MD5值的命令

    今天需要,就记录一下. certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile file ...

  3. 利用Python计算π的值,并显示进度条

    利用Python计算π的值,并显示进度条  第一步:下载tqdm 第二步;编写代码 from math import * from tqdm import tqdm from time import ...

  4. JAVA中获取文件MD5值的四种方法

    JAVA中获取文件MD5值的四种方法其实都很类似,因为核心都是通过JAVA自带的MessageDigest类来实现.获取文件MD5值主要分为三个步骤,第一步获取文件的byte信息,第二步通过Messa ...

  5. 基于js-spark-md5前端js类库,快速获取文件Md5值

    js-spark-md5是歪果仁开发的东西,有点多,但是我们只要一个js文件即可,具体类包我存在自己的oschina上,下载地址:https://git.oschina.net/jianqingwan ...

  6. C#统计目录中文件MD5值

    1. [代码]统计目录中文件MD5值 using System.IO;using System.Security.Cryptography;using System.Collections;using ...

  7. MD5工具类,提供字符串MD5加密、文件MD5值获取(校验)功能

    MD5工具类,提供字符串MD5加密(校验).文件MD5值获取(校验)功能 : package com.yzu.utils; import java.io.File; import java.io.Fi ...

  8. QT 获取文件MD5值

    /* 方法1 */ QFile theFile(fileNamePath); theFile.open(QIODevice::ReadOnly); QByteArray ba = QCryptogra ...

  9. C# 获取文件MD5值的方法

    可用于对比文件是否相同 /// <summary> /// 获取文件MD5值 /// </summary> /// <param name="fileName& ...

随机推荐

  1. Vue 路由配置、动态路由

    1.安装 npm install vue-router --save / cnpm install vue-router --save 2.引入并 Vue.use(VueRouter) (main.j ...

  2. HP-UX oracle RAC 双机实践 (转载)

    一.软硬件配置检查 1.检查内存#/usr/contrib/bin/machinfoCPU info:  4 Intel(R) Itanium 2 9100 series processors (1. ...

  3. php变量详细讲解

    变量是用于存储信息的"容器". 定义一个变量的语法: $变量名 = 值; 使用变量的例子: <?php $x=5; $y=6; $z=$x+$y; echo $z; ?> ...

  4. EMNLP 2018 | 用强化学习做神经机器翻译:中山大学&MSRA填补多项空白

    人工深度学习和神经网络已经为机器翻译带来了突破性的进展,强化学习也已经在游戏等领域取得了里程碑突破.中山大学数据科学与计算机学院和微软研究院的一项研究探索了强化学习在神经机器翻译领域的应用,相关论文已 ...

  5. linux read 系统调用剖析

    https://www.ibm.com/developerworks/cn/linux/l-cn-read/ MT注:原文图1与Understanding the Linux Kernel, 3rd ...

  6. 网络虚拟化中的 offload 技术:LSO/LRO、GSO/GRO、TSO/UFO、RSS、VXLAN

    offload offload特性,主要是指将本来在操作系统协议栈中进行的一些数据包处理(如IP分片.TCP分片.重组.checksum校验等)放到网卡硬件中去做,降低系统 CPU 消耗,提高处理的性 ...

  7. django 更新 模板语言

    Django模板系统 官方文档 常用语法 只需要记两种特殊符号: {{  }}和 {% %} 变量相关的用{{}},逻辑相关的用{%%}. 变量 在Django的模板语言中按此语法使用:{{ 变量名 ...

  8. WGCNA 分析

    https://www.jianshu.com/p/f80de3468c04 https://mp.weixin.qq.com/s/-DthUKY2RTY6vxtxapzLkw https://www ...

  9. 高斯混合模型(理论+opencv实现)

    查资料的时候看了一个不文明的事情,转载别人的东西而不标注出处,结果原创无人知晓,转载很多人评论~~标注了转载而不说出处这样的人有点可耻! 写在前面: Gaussian Mixture Model (G ...

  10. 字符串,数组,定时器,form

    一.字符串 <script> /* // 字符串的属性 var a="hello world"; console.log(a.length); console.log( ...