代码拉取完成,页面将自动刷新
# -*- coding:utf-8 -*-
import hashlib
import os
import sys
def get_file_md5(path):
"""
获取文件内容的MD5值
:param path: 文件所在路径
:return:
"""
with open(path, 'rb') as file:
data = file.read()
diff_check = hashlib.md5()
diff_check.update(data)
md5_code = diff_check.hexdigest()
return md5_code
def get_size(path):
# 获取path目录下所有文件
for filename in os.listdir(path):
pathTmp = os.path.join(path, filename) # 获取path与filename组合后的路径
# if os.path.isdir(pathTmp): # 判断是否为目录
# get_size(pathTmp) # 是目录就继续递归查找
# elif os.path.isfile(pathTmp): # 判断是否为文件
# filesize = os.path.getsize(pathTmp) # 如果是文件,则获取相应文件的大小
if os.path.isfile(pathTmp):
filesize = os.path.getsize(pathTmp)
file_list[filename] = filesize # 将文件的大小添加到字典
return file_list
path = '/home/quanzong/factory'
file_list = {}
if __name__ == '__main__':
try:
get_size(path)
for item in file_list.keys():
path_full = os.path.join(path, item)
write_line = "{0}\t{1}\t{2}\n".format(item, file_list[item], get_file_md5(path_full))
result = "result.txt"
with open(os.path.join(path, result), 'a') as output:
output.write(write_line)
except Exception:
print("something wrong,plz check.")
sys.exit()
print("all set,go to {0},find the result.txt".format(path))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。