Need to zip and password protect files in as few steps as possible

12

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?

DAE

Posted 2017-03-12T08:44:01.833

Reputation: 223

Answers

19

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

Use the -p option:

-p (set Password) switch

Specifies password.

Syntax

 -p{password}
  • {password} Specifies password.

Examples

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

DavidPostill

Posted 2017-03-12T08:44:01.833

Reputation: 118 938

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 – 2017-03-12T09:11:13.500

See the example in my answer :) – DavidPostill – 2017-03-12T09:12:11.057

but I'm not compressing .txt files, I'm compressing folders – DAE – 2017-03-12T09:15:20.487

@DAE That shouldn't matter. "c:\Program Files (x86)\7-Zip\7z.exe" a "%%X.zip" -psecret "%%X\". – DavidPostill – 2017-03-12T09:17:46.230

excellent- that answered the question. thanks! – DAE – 2017-03-12T09:19:47.950

2beware 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 – 2017-03-13T03:54:04.803

Any idea what to do if this results in "The parameter is incorrect"? It's related to the mhe flag, which I want to use but I can't get it to work. – nasch – 2018-06-29T01:17:16.427

-1

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

Dayana Pears

Posted 2017-03-12T08:44:01.833

Reputation: 1

Welcome to Superuser. Please try to contain most relevant information from the link in your post. Read more about it here.

– styrofoam fly – 2017-07-02T14:56:01.963