I need to create a zip archive with a custom extension of ‘.stz’ as this is the only file format accepted by the application it will be used in. Using shutil.make_archive the file always has the .zip file extension even if not specified by me. Currently just renaming it after creation. Is there a better way to do this?
import os
import shutil
output = “file.stz”
dir_name = “files/“
zip_name = shutil.make_archive(‘tmp’, ‘zip’, dir_name)
os.rename(zip_name, output)
You could use shutil.register_archive_format
to register your own extension, but still compress it as a zip file. This is more code but does allow you to skip your rename step.
def stzCompress():
pass
shutil.register_archive_format('stz', stzCompress, description='stz file')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With