因为需要从.zip file里面找到所有animations (例如从一个目录就好了)
自己写了一下
-- 当然大部分是AI写的
-- 毕竟我也是从年初 Deepseek那一波,才开始写python
完全不懂Python嘛,零基础
刚好,在LOL英雄联盟还在下载到一半的时候,已经写好了
一开始就两个代码,其中一个我直接照搬的,名字都没改
import zipfile
import os
import argparse
def search_zip_content(search_term, zip_folder):
for root, dirs, files in os.walk(zip_folder):
for file in files:
if file.endswith('.zip'):
zip_path = os.path.join(root, file)
with zipfile.ZipFile(zip_path, 'r') as zf:
for info in zf.infolist():
if search_term in info.filename:
print(f"Found in {zip_path}: {info.filename}")
# 如需搜索文本内容,可进一步读取文件
def search_zip_dir(search_term, zip_folder):
for root, dirs, files in os.walk(zip_folder):
for file in files:
if file.endswith('.zip'):
zip_path = os.path.join(root, file)
for inner_dir in get_zip_directories(zip_path):
if search_term in inner_dir:
print(f'dir name={file}')
print(inner_dir)
再问问AI
#readZipFiles.py
import zipfile
import os
import argparse
def search_zip_content(search_term, zip_folder):
for root, dirs, files in os.walk(zip_folder):
for file in files:
if file.endswith('.zip'):
zip_path = os.path.join(root, file)
with zipfile.ZipFile(zip_path, 'r') as zf:
for info in zf.infolist():
if search_term in info.filename:
print(f"Found in {zip_path}: {info.filename}")
# 如需搜索文本内容,可进一步读取文件
def search_zip_dir(search_term, zip_folder):
for root, dirs, files in os.walk(zip_folder):
for file in files:
if file.endswith('.zip'):
zip_path = os.path.join(root, file)
for inner_dir in get_zip_directories(zip_path):
if search_term in inner_dir:
print(f'dir name={file}')
print(inner_dir)
def get_zip_directories(zip_path):
directories = set()
with zipfile.ZipFile(zip_path, 'r') as zf:
for info in zf.infolist():
if info.filename.endswith('/'): # 纯目录(带末尾斜杠)
dir_name = info.filename.rstrip('/') # 去除末尾斜杠
directories.add(dir_name)
return directories
def main():
parser = argparse.ArgumentParser(description='获取 ZIP 文件内的目录信息')
parser.add_argument('zip_path', type=str, help='ZIP 文件的路径')
parser.add_argument('searchkey',type=str,help="要查找的目录 models|animations|textures|...")
parser.add_argument('--include_file_parent', action='store_true',
help='是否包含文件所在的父目录,默认包含')
parser.add_argument('--recursive', action='store_true',
help='是否递归提取所有层级的目录,默认不递归')
args = parser.parse_args()
print(f'main() p={args.zip_path}')
search_zip_dir(args.searchkey,args.zip_path)
if __name__ == "__main__":
main()
这是我写的最终版本
调用方法