Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# python3
1. download sb3 and unzip
* box2d_2_codelab_start.sb3
* rename box2d_2_codelab_start.sb3 ->
* unzip it: -> box2d_2_codelab_start
2. Modify content
3. zip box2d_2_codelab_start
* cd box2d_2_codelab_start
* python
* output: /tmp/output.sb3
# todo 路径问题,处于顶层
from zipfile import ZipFile, ZIP_DEFLATED # 3.7才能使用level
import os
path = "." # 当前目录
output_file = "/tmp/output.sb3"
print('creating archive')
with ZipFile(output_file, 'w') as zf:
for current_path, subfolders, filesname in os.walk(path):
# print(current_path, subfolders, filesname)
# filesname是一个列表,我们需要里面的每个文件名和当前路径组合
for file in filesname:
if "" in file:
# 将当前路径与当前路径下的文件名组合,就是当前文件的绝对路径
file_path = os.path.join(current_path, file)
zf.write(file_path, compress_type=ZIP_DEFLATED)
print('finish archive')

This comment has been minimized.

Copy link
Owner Author

@wwj718 wwj718 commented Jan 28, 2019

cd sb3_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment