V
V
Valery Zhmyshenko2021-01-14 20:14:11
Python
Valery Zhmyshenko, 2021-01-14 20:14:11

Why is a password not set for the archive?

import zipfile

z = zipfile.ZipFile('BEK.zip', 'w')  
z.setpassword(b"1234")      
for root, dirs, files in os.walk('/path/to/file'): # Список всех файлов и папок в директории folder
    for file in files:
        z.write(os.path.join(root,file))         # Создание относительных путей и запись файлов в архив

z.close()

The archive itself is created, but there is no password on it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2021-01-14
@mcborrrov

The zipfile library cannot put a password on an archive. The setpassword method is needed to set a password for extracting encrypted files.
In your case, you need to use pyminizip.

D
Dr. Bacon, 2021-01-14
@bacon

Yeah, and who will read the docs https://docs.python.org/3/library/zipfile.html#zip...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question