利用python计算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
结果如下

利用python计算windows全盘文件md5值的脚本的更多相关文章
- java计算过G文件md5 值计算
package io.bigdata; import java.io.File; import java.io.FileInputStream; import java.io.IOException; ...
- windows查看文件MD5值的命令
今天需要,就记录一下. certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile file ...
- 利用Python计算π的值,并显示进度条
利用Python计算π的值,并显示进度条 第一步:下载tqdm 第二步;编写代码 from math import * from tqdm import tqdm from time import ...
- JAVA中获取文件MD5值的四种方法
JAVA中获取文件MD5值的四种方法其实都很类似,因为核心都是通过JAVA自带的MessageDigest类来实现.获取文件MD5值主要分为三个步骤,第一步获取文件的byte信息,第二步通过Messa ...
- 基于js-spark-md5前端js类库,快速获取文件Md5值
js-spark-md5是歪果仁开发的东西,有点多,但是我们只要一个js文件即可,具体类包我存在自己的oschina上,下载地址:https://git.oschina.net/jianqingwan ...
- C#统计目录中文件MD5值
1. [代码]统计目录中文件MD5值 using System.IO;using System.Security.Cryptography;using System.Collections;using ...
- MD5工具类,提供字符串MD5加密、文件MD5值获取(校验)功能
MD5工具类,提供字符串MD5加密(校验).文件MD5值获取(校验)功能 : package com.yzu.utils; import java.io.File; import java.io.Fi ...
- QT 获取文件MD5值
/* 方法1 */ QFile theFile(fileNamePath); theFile.open(QIODevice::ReadOnly); QByteArray ba = QCryptogra ...
- C# 获取文件MD5值的方法
可用于对比文件是否相同 /// <summary> /// 获取文件MD5值 /// </summary> /// <param name="fileName& ...
随机推荐
- TensorFlow相关的一些技巧
谷歌开发技术推广工程师 Laurence Moroney 在 Google Cloud Next 大会上进行了一段 42 分钟的演讲,主题是「What's New with TensorFlow?」. ...
- 经典算法 Manacher算法详解
内容: 1.原始问题 =>O(N^2) 2.Manacher算法 =>O(N) 1.原始问题 Manacher算法是由题目“求字符串中长回文子串的长度”而来.比如 abcdcb 的 ...
- 2017-2018-2 20165233 实验四 Android程序设计
20165233 实验四 Android程序设计 实验内容 任务一: 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Andr ...
- OpenCL 双调排序 GPU 版
▶ 参考书中的代码,写了 ● 代码,核函数文件包含三中算法 // kernel.cl __kernel void bitonicSort01(__global uint *data, const ui ...
- linux 使用随笔
目录:1,ab命令 一,ab命令 ab网站压力测试命令的参数.输出结果的中文注解 ab命令是Apache的Web服务器的性能测试工具,它可以测试安装Web服务器每秒种处理的HTTP请求. 来自: ht ...
- css之为文本添加线性渐变和外描边
css之为文本添加线性渐变和外描边 一.效果: 描边:描边+渐变: 二.描边: api:text-stroke 问题:text-stroke的描边是居中描边,无法直接设置外描边 解决:在before ...
- 一个NPOI导出到excel文件的范例记录
'使用NPOI写入新创建的excel文件,导出文件: Private Sub Sub_WriteXls() Dim XlsBook As XSSFWorkbook Dim XlsSheet As XS ...
- 【转】Maven中-DskipTests和-Dmaven.test.skip=true的区别
主要区别是:是否编译测试类 -DskipTests:编译测试类,但不运行 -Dmaven.test.skip=true:不编译.不运行 转自 http://zephiruswt.blog.51cto. ...
- mybatis - maven - eclipse 坑爹问题: No suitable driver found for http://maven.apache.org
坑爹的问题,调查了1天 一直以为是驱动问题,根源却在url上:No suitable driver found for http://maven.apache.org 根源: 1.在jdbc.prop ...
- SourceTree使用方法
一 .SourceTree简介 SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端,拥有可视化界面,容易上手操作.同时它也是Mercurial和Subve ...