deftranverse(dir: str): """ 遍历给定文件夹,并返回所有文件(不含文件夹)路径组成的数组 """ ret = [] for root, dirs, files in os.walk(dir): for file in files: ret.append(os.path.join(root, file)) return ret
defmd5_file(file: str) -> str: """ 计算给定文件的 md5 """ with open(file, 'rb') as file: return hashlib.md5(file.read()).hexdigest()