|
import os |
|
import zipfile |
|
|
|
def zip_subdirectories(parent_directory, target_directory): |
|
if not os.path.exists(target_directory): |
|
os.mkdir(target_directory) |
|
for foldername, subfolders, filenames in os.walk(parent_directory): |
|
|
|
for subfolder in subfolders: |
|
zip_path = os.path.join(target_directory, f"{subfolder}.zip") |
|
|
|
with zipfile.ZipFile(zip_path, 'w') as zipf: |
|
subfolder_path = os.path.join(foldername, subfolder) |
|
|
|
for root, _, files in os.walk(subfolder_path): |
|
for file in files: |
|
|
|
file_path = os.path.join(root, file) |
|
|
|
arcname = os.path.join(subfolder, os.path.relpath(file_path, start=subfolder_path)) |
|
|
|
zipf.write(file_path, arcname) |
|
|
|
break |
|
|
|
|
|
zip_subdirectories('/mnt/petrelfs/zhuchenglin/LLaVA/playground/data/eval/gqa/data', '/mnt/hwfile/zhuchenglin/playground/eval/gqa/data') |
|
|