WhoYoung99
WhoYoung99

Reputation: 13

How's python Pyminizip compress_multiple work?

My python version is 3.5 through Anaconda on Windows 10 environment. I'm using Pyminizip because I need password protected for my zip files, and Zipfile doesn't support it yet.

I am able to zip single file through the function pyminizip.compress, and the encrypt function worked as expected. However, when trying to use pyminizip.compress_multiple I always encountered a Python crash (as pictures) and I believe it's due to the problem of my bad input format.

What I would like to know is: What's the acceptable format for input argument src file LIST path? From Pyminizip's documentation:

pyminizip.compress_multiple([u'pyminizip.so', 'file2.txt'], "file.zip", "1233", 4, progress)
Args:
1. src file LIST path (list)
2. dst file path (string)
3. password (string) or None (to create no-password zip)
4. compress_level(int) between 1 to 9, 1 (more fast) <---> 9 (more compress)

It seems the first argument src file LIST path should be a list containing all files required to be zipped. Accordingly, I tried to use compress_multiple to compress single file with command:

pyminizip.compress_multiple( ['Filename.txt'], 'output.zip', 'password', 4, optional)

and it lead to Python crash. So I try to add a full path into the args.

pyminizip.compress_multiple( [os.getcwd(), 'Filename.txt'], ... )

and still, it crashed again. So I think maybe I have to split the path like this

path = os.getcwd().split( os.sep )
pyminizip.compress_multiple( [path, 'Filename.txt'], ...)

still got a bad luck. Any ideas?

Upvotes: 1

Views: 6236

Answers (2)

user1260486
user1260486

Reputation: 315

From here - https://pypi.org/project/pyminizip/, the usage of compress_multiple is

pyminizip.compress_multiple([u'pyminizip.so', 'file2.txt'], [u'/path_for_file1', u'/path_for_file2'], "file.zip", "1233", 4, progress)

The second parameter is a bit confusing, but if used, it will create a zip file, which when uncompressed, will create a directory structure like:

enter image description here

Upvotes: 0

J.A. Simmons V
J.A. Simmons V

Reputation: 176

Pyminizip requires the path name (or relative path name from where the script is running from) in the files.

Your example:

pyminizip.compress_multiple( [os.getcwd(), 'Filename.txt'], ... )

gives a list of files of os.getcwd(), and then another file, 'Filename.txt'. You need to combine them into a single path using os.path.join()

in your filename example, you will need:

pyminizip.compress_multiple( [os.path.join(getcwd(), 'Filename.txt')],...)

conversly:

pyminizip.compress_multiple( [os.path.join(getcwd(), 'Filename1.txt'), os.path.join(getcwd(), 'Filename2.txt')],...)

Upvotes: 2

Related Questions