import zipfile
target = 'zip-test.py'
handle = zipfile.ZipFile('BACKUP.zip', 'w')
handle.write(target, compress_type = zipfile.ZIP_DEFLATED)
handle.close()
This Python script creates a new Zip archive named "BACKUP.zip" and adds a file named "zip-test.py" to it. The file is compressed using the "DEFLATED" compression method, which is one of the standard compression methods supported by the Zip format.
The first line imports the "zipfile" module, which provides classes and functions for working with Zip archives.
The second line creates a new Zip archive named "BACKUP.zip" in write mode ('w') using the "ZipFile" class from the "zipfile" module.
The third line adds the file named "zip-test.py" to the Zip archive using the "write" method of the ZipFile object. The "compress_type" parameter specifies the compression method to use, in this case "ZIP_DEFLATED".
The fourth line closes the Zip archive using the "close" method of the ZipFile object.
No comments:
Post a Comment