Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# python3
'''
usage
1. download sb3 and unzip
* box2d_2_codelab_start.sb3
* rename box2d_2_codelab_start.sb3 -> box2d_2_codelab_start.zip
* unzip it: -> box2d_2_codelab_start
2. Modify content
3. zip box2d_2_codelab_start
* cd box2d_2_codelab_start
* python sb3_compress.py
* 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 "sb3_compress.py" in file:
continue
print(file)
# 将当前路径与当前路径下的文件名组合,就是当前文件的绝对路径
file_path = os.path.join(current_path, file)
zf.write(file_path, compress_type=ZIP_DEFLATED)
print('finish archive')
@wwj718

This comment has been minimized.

Copy link
Owner Author

wwj718 commented Jan 28, 2019

cd sb3_dir
wget https://gist.githubusercontent.com/wwj718/cd2447e68409a0f36141f4d1d7698fd9/raw/144058c49ea6c8bfd501e2c28dd19c6d61278269/sb3_compress.py
python3 sb3_compress.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.