|
import os |
|
import zipfile |
|
from pathlib import Path |
|
|
|
def zip_folder(folder_path, output_path): |
|
""" |
|
压缩单个文件夹 |
|
""" |
|
folder = Path(folder_path) |
|
with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf: |
|
for file in folder.rglob('*'): |
|
zipf.write(file, file.relative_to(folder.parent)) |
|
print(f"✅ Zipped {folder} -> {output_path}") |
|
|
|
def zip_all_scenes(root_dir): |
|
""" |
|
扫描 Real, Hypothetical, Multi_View 文件夹,自动打包每个 scene |
|
""" |
|
root = Path(root_dir) |
|
categories = ["Real", "Hypothetical", "Multi_View"] |
|
|
|
for category in categories: |
|
category_path = root / category |
|
if not category_path.exists(): |
|
print(f"⚠️ Skip {category}: not found") |
|
continue |
|
|
|
for scene in category_path.iterdir(): |
|
if scene.is_dir(): |
|
output_zip = root / f"{category}_{scene.name}.zip" |
|
zip_folder(scene, output_zip) |
|
|
|
if __name__ == "__main__": |
|
|
|
zip_all_scenes(".") |
|
|
|
print("✅ All scenes zipped successfully.") |