1 Star 0 Fork 0

Ragus/pycs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file_checksum.py 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
import os
import hashlib
# 计算文件的md5sum
def md5sum(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
# 获取全部文件后缀名
def get_suffix_and_filelist(path):
sfx=[]
fls=[]
for p,ds,fs in os.walk(path):
for f in fs:
fn = os.path.join(p,f)
fls.append(fn)
sf = os.path.splitext(fn)[1]
if sf not in sfx:
sfx.append(sf)
return sfx,fls
# 文件后缀,文件列表
path = "your/pathname/"
suffix,flists = get_suffix_and_filelist(path)
with open(os.path.join(path,"checksumAll.txt"),"w") as fr:
for fl in flists:
if os.path.splitext(fl)[1] in ['.jpg', '.png', '.MOV', '.JPG', '.PNG', '.GIF']:
fn = fl
fmd = md5sum(fl)
print("%s:%s" %(fn,fmd))
fr.write(fn + ":" + fmd + "\n")
else :
print(fl + " not in list")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/ragus/pycs.git
git@gitee.com:ragus/pycs.git
ragus
pycs
pycs
master

搜索帮助