Skip to main content
Re-formating, listing, highlighting part of code, & English fixes.
Source Link
Maher Abuthraa
  • 17.7k
  • 12
  • 84
  • 105

@tripleee 's@tripleee's answer helped me, so I putsee my test in the below, hope it will help also.

The following oneThis code works for me, on python 3.5.2, windows8 on Windows 8.1, 7z ( 7z path added to system).

    rc = subprocess.call(['7z', 'a', output_filename + '.zip', '-mx9', '-pSecret^)'] + [src_folder + '/'])

With two parameters, -mx9 means max compression, -pSecret^) means password is "Secret^)" , "^" is escape for ")"for windows system, but when you unzip, it will need type in the "^".:

  1. -mx9 means max compression
  2. -pSecret^) means password is Secret^). ^ is escape for ) for Windows OS, but when you unzip, it will need type in the ^.

Without "^", windows system^ Windows OS will not apply the password when 7z.exe creating the zipzip file.

Also, if you want to use "-mhe"-mhe switch, youyou'll need the file format to be in 7z7z instead of zipzip.

I hope that may help.

@tripleee 's answer helped me, so I put my test in the below, hope it will help also.

The following one works for me, python 3.5.2, windows8.1, 7z path added to system

    rc = subprocess.call(['7z', 'a', output_filename + '.zip', '-mx9', '-pSecret^)'] + [src_folder + '/'])

With two parameters, -mx9 means max compression, -pSecret^) means password is "Secret^)" , "^" is escape for ")"for windows system, but when you unzip, it will need type in the "^".

Without "^", windows system will not apply the password when 7z.exe creating the zip file.

Also, if you want to use "-mhe" switch, you need file format in 7z instead of zip.

@tripleee's answer helped me, see my test below.

This code works for me on python 3.5.2 on Windows 8.1 ( 7z path added to system).

rc = subprocess.call(['7z', 'a', output_filename + '.zip', '-mx9', '-pSecret^)'] + [src_folder + '/'])

With two parameters:

  1. -mx9 means max compression
  2. -pSecret^) means password is Secret^). ^ is escape for ) for Windows OS, but when you unzip, it will need type in the ^.

Without ^ Windows OS will not apply the password when 7z.exe creating the zip file.

Also, if you want to use -mhe switch, you'll need the file format to be in 7z instead of zip.

I hope that may help.

Source Link
zqcolor
  • 330
  • 2
  • 5
  • 14

@tripleee 's answer helped me, so I put my test in the below, hope it will help also.

The following one works for me, python 3.5.2, windows8.1, 7z path added to system

    rc = subprocess.call(['7z', 'a', output_filename + '.zip', '-mx9', '-pSecret^)'] + [src_folder + '/'])

With two parameters, -mx9 means max compression, -pSecret^) means password is "Secret^)" , "^" is escape for ")"for windows system, but when you unzip, it will need type in the "^".

Without "^", windows system will not apply the password when 7z.exe creating the zip file.

Also, if you want to use "-mhe" switch, you need file format in 7z instead of zip.