利用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& ...
随机推荐
- R语言中的遗传算法详细解析
前言 人类总是在生活中摸索规律,把规律总结为经验,再把经验传给后人,让后人发现更多的规规律,每一次知识的传递都是一次进化的过程,最终会形成了人类的智慧.自然界规律,让人类适者生存地活了下来,聪明的科学 ...
- 使用promisify来流程化异步操作
现代js包括nodejs中有很多函数都是异步执行的, 我们总是需要写一个回调函数并且作为最后以一个参数传入,而我希望的是能像写promise这样的回调 promise .then() .then() ...
- 9.简单理解ajax
#### post 请求需要发送一个header setRequestHeader('Content-Type','application/x-www-form-urlencoded') post请求 ...
- 基于request.getAttribute与request.getParameter的区别详解
HttpServletRequest类既有getAttribute()方法,也有getParameter()方法,这两个方法有以下区别:1.HttpServletRequest类有setAttribu ...
- 1. SVN clean失败解决方法
svn执行clean up后出现提示:svn cleanup failed–previous operation has not finished; run cleanup if it was int ...
- three添加和移除对象
创建场景在第一章的地方就讲过怎么样创建一个最基本的场景,这里不重复了html:部分 <!doctype html><html lang="en"><h ...
- c# DbProviderFactories 多数据库支持工程模式
DbProviderFactories.GetFactory(dbProviderName) DBProviderFactory factory = DBProviderFactorys.GetFac ...
- UI5-文档-1-前言
主要是将SAP UI5官网文档做下了解,相关内容请查阅:https://sapui5.hana.ondemand.com/#/topic 设置您的开发环境并阅读我们的教程.它们使用交互式格式中的实际示 ...
- Unified shader model
https://en.wikipedia.org/wiki/Unified_shader_model In the field of 3D computer graphics, the Unified ...
- 发送电子邮件模块smtplib
功能:smtplib模块是通过邮件服务器发送电子邮件,是smtp客户端的实现,支持邮件格式有:文本.HTML.Image.EXCEL等. 1 #!/usr/bin/env python 2 # cod ...