1.
#input folder zip
import shutil
shutil.make_archive(output_filename, 'zip', input_folder_name)
2.
#특정 extension만 recursive하게 zip
import os
import zipfile
EXTENSION=['jpg', 'JPG']
def zip_folder(input_folder_path, output_zip_path):
with zipfile.ZipFile(output_zip_path, mode='w') as zipf:
len_dir_path = len(input_folder_path)
for root, _, files in os.walk(input_folder_path):
for file in files:
if file.endswith(EXTENSION):
file_path = os.path.join(root, file)
zipf.write(file_path, file_path[len_dir_path:])
zip_folder('path/to/input_directory', 'path/to/output_zip')
'Python' 카테고리의 다른 글
python parameter에서 bare *란? (0) | 2022.06.20 |
---|---|
python xxx is not a package (0) | 2022.03.21 |
(에러)RuntimeError: Task <Task pending name='Task-1' coro=<update_one() running at test.py:7> cb=[_run_until_complete_cb() (0) | 2021.12.17 |
os.system significantly take time more than shutil. (0) | 2021.12.15 |
(에러)Asyncssh error Host key is not trusted (0) | 2021.11.15 |