I need a way to take a bunch of files and compress them into separate zip files, each with a password (the same password). I want to be able to do this in one simple step.

I have created a batch file that zips them each using 7zip, which worked like a charm, but didn't password protect them.

Is there a command I can add to the batch file that includes the password? Or alternatively - how can i create a batch file that will password protect the compressed files?


2 Answers 2


How can I create a batch file that will password protect the compressed files?

Use the -p option:

-p (set Password) switch

Specifies password.


  • {password} Specifies password.


7z a archive.7z -psecret -mhe *.txt

compresses *.txt files to archive.7z using password "secret". Also it encrypts archive headers (-mhe switch), so filenames will be encrypted.

7z x archive.zip -psecret

extracts all files from archive.zip using password "secret".

Source -p (set Password) switch

  • Thanks! If this is my batch file - where should i place that switch? for /d %%X in (*) do "c:\Program Files (x86)\7-Zip\7z.exe" a "%%X.zip" "%%X\"
    – DAE
    Commented Mar 12, 2017 at 9:11
  • See the example in my answer :)
    – DavidPostill
    Commented Mar 12, 2017 at 9:12
  • but I'm not compressing .txt files, I'm compressing folders
    – DAE
    Commented Mar 12, 2017 at 9:15
  • @DAE That shouldn't matter. "c:\Program Files (x86)\7-Zip\7z.exe" a "%%X.zip" -psecret "%%X\".
    – DavidPostill
    Commented Mar 12, 2017 at 9:17
  • 2
    beware that this puts the password in your command history. On Windows, this should persist for the current shell, but on nix, it typically persists longer. additionally, the command line is visible *all other processes on the system for the duration of the process execution. If any untrusted software is on the system, you may have just given it your secret.
    – atk
    Commented Mar 13, 2017 at 3:54

The easiest way I know of is like this: http://www.winzip.com/win/en/features/data-protection.html I can not promise that it's the safest but I've been using it for a very long time and never had a problem. Let me know how it worked out

  • Welcome to Superuser. Please try to contain most relevant information from the link in your post. Read more about it here. Commented Jul 2, 2017 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .