7-Zip command to create and extract a password-protected ZIP file on Windows? [closed]
From http://www.dotnetperls.com:
7z a secure.7z * -pSECRET
Where:
7z : name and path of 7-Zip executable
a : add to archive
secure.7z : name of destination archive
* : add all files from current directory to destination archive
-pSECRET : specify the password "SECRET"
To open :
7z x secure.7z
Then provide the SECRET password
Note: If the password contains spaces or special characters, then enclose it with single quotes
7z a secure.7z * -p"pa$$word @|"
General Syntax:
7z a archive_name target parameters
Check your 7-Zip dir. Depending on the release you have, 7z may be replaced with 7za in the syntax.
Parameters:
- -p encrypt and prompt for PW.
- -pPUT_PASSWORD_HERE (this replaces -p) if you want to preset the PW with no prompt.
- -mhe=on to hide file structure, otherwise file structure and names will be visible by default.
Eg. This will prompt for a PW and hide file structures:
7z a archive_name target -p -mhe=on
Eg. No prompt, visible file structure:
7z a archive_name target -pPUT_PASSWORD_HERE
And so on. If you leave target blank, 7z will assume * in current directory and it will recurs directories by default.
To fully script-automate:
Create:
7z -mhc=on -mhe=on -pPasswordHere a %ZipDest% %WhatYouWantToZip%
Unzip:
7z x %ZipFile% -pPasswordHere
(Depending, you might need to: Set Path=C:\Program Files\7-Zip;%Path% )