没有合适的资源?快使用搜索试试~ 我知道了~
给你个ipa包,解压前输出包大小,解压后把里面的文件按大小排序。 代码如下: import os import shutil import zipfile _ipa_zip_path = lambda ipa_path: ipa_path.replace('.ipa', '.zip') _file_size = lambda file_path: os.path.getsize(file_path) / 1024 / 1024 def unzip(zip_path: str) -> str: dir_path = None if zip_path.endswith('.zip'):
资源详情
资源评论
资源推荐
Python3将将ipa包中的文件按大小排序包中的文件按大小排序
给你个ipa包,解压前输出包大小,解压后把里面的文件按大小排序。
代码如下:
import os
import shutil
import zipfile
_ipa_zip_path = lambda ipa_path: ipa_path.replace('.ipa', '.zip')
_file_size = lambda file_path: os.path.getsize(file_path) / 1024 / 1024
def unzip(zip_path: str) -> str:
dir_path = None
if zip_path.endswith('.zip'):
print(f'{zip_path} file size:{round(_file_size(zip_path),3)}mb')
zip_name = os.path.basename(zip_path)
dir_name = zip_name.replace('.zip', '')
dir_root_path = zip_path.replace(zip_name, '')
dir_path = os.path.join(dir_root_path, dir_name)
if os.path.exists(dir_path):
shutil.rmtree(dir_path)
os.mkdir(dir_path)
zip_file = zipfile.ZipFile(zip_path)
for file_name in zip_file.namelist():
zip_file.extract(file_name, dir_path)
zip_file.close()
return dir_path
def rename_suffix(raw, raw_type, target) -> None:
if raw.endswith(raw_type) and os.path.exists(raw):
os.rename(raw, target)
def walk_files(dir_path) -> list:
file_dicts = [] if os.path.exists(dir_path):
for root, dirs, files in os.walk(dir_path, topdown=True):
for name in files:
file_path = os.path.join(root, name)
file_dict = {
'file_name': name,
'file_size': round(_file_size(file_path), 8),
}
file_dicts.append(file_dict)
return file_dicts
def show_files_size(dir_path=None) -> None:
if dir_path:
file_dicts_sorted = sorted(walk_files(dir_path),
key=lambda e: (e.__getitem__('file_size'), e.__getitem__('file_name')), reverse=True)
for file_dict in file_dicts_sorted:
print(f'{file_dict["file_name"]}->{file_dict["file_size"]}mb')
def ipa_checker(ipa_path: str) -> None:
try:
ipa_file_size = _file_size(ipa_path)
print(f'{ipa_path} file size:{round(ipa_file_size,3)}mb')
except FileNotFoundError as error:
print(f'File not exists->{ipa_path}')
ipa_zip_path = _ipa_zip_path(ipa_path)
rename_suffix(ipa_path, '.ipa', ipa_zip_path)
try:
dir_path = unzip(ipa_zip_path)
show_files_size(dir_path)
except OSError as error:
print(error)
if __name__ == '__main__':
weixin_38686153
- 粉丝: 11
- 资源: 888
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0