import zipfile def read_zip(zip_file_path: str, unpack_path: str, ws_msg: WebSocketMsg): """ 解压ZIP文件 @param zip_file_path: ZIP文件路径(ex. E:\aaa\a.zip) @param unpack_path: 解压文件输出路径(ex. E:\aaa) @param ws_msg: 用来放实时进度的类(可干掉) """ file_list = zipfile.ZipFile(zip_file_path) info = file_list.infolist() ''' 1 计算解压后的文件总大小(单位:字节B) ''' all_size = 0 for i in info: all_size += i.file_size # 1.1 字节B转换为兆字节MB (字符串) all_size_str = str(int(all_size / 1024 / 1024)) + 'MB' ''' 2 当前已解压的文件总大小(单位:字节B) ''' now_size = 0 for i in info: file_list.extract(i, unpack_path) now_size += i.file_size # 2.1 字节B转换为兆字节MB (字符串) now_size_str = str(int(now_size / 1024 / 1024)) + 'MB' ws_msg.msg.append(f'解压进度:{int(now_size / all_size * 100)}% ({now_size_str}/{all_size_str})') # print(f'解压进度:{int(now_size / all_size * 100)}% ({now_size_str}/{all_size_str})') file_list.close()
【Python】解压文件/ZIP等 并实时计算解压进度
免责声明:文章转载自《【Python】解压文件/ZIP等 并实时计算解压进度》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇[转载]fullPage.js中文api 配置参数~【js基本功能模块】“回到顶部”代码优化下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=