Link to home
Start Free TrialLog in
Avatar of Glyn Merritt
Glyn Merritt

asked on

Simple password protected zip file creation on windows desktop

I'd like to create a bat file or smiler that you can drag and drop a file onto and the bat file zips it up files dropped on with a predefined password.

It would be great if I could use 7zip or similar and not have to buy a utility.

Many thanks in advance
Avatar of joinaunion
joinaunion
Flag of Canada image

Avatar of Glyn Merritt
Glyn Merritt

ASKER

This is exactly what I want to do but with all the manual steps cut out.

The idea is that instead of having to right mouse click select add to archive change the archive to zip format and type in a password etc... they just drop the file they wish to zip and password protect onto an icon on the desktop and then it creates a zip file that is protected with a predefined password.
Try this for starters. It creates the archive based on name and the location of the original file, with the extension .zip.
Do you need to process several files dropped at the same time as well (and if so, do you want individual archives for each file, or one archive file)?
What if a folder is dropped on the script?
@echo off
setlocal
set "Password=Top & Secret"
set SevenZip=%ProgramFiles%\7-Zip\7z.exe
if "%~1"=="" goto :eof
"%SevenZip%" a -o"%~dp1" -p"%Password%" -tzip "%~n1.zip" "%~1"
if errorlevel 1 (
	color 4f
	pause
)

Open in new window

That looks great.

It would be superb if it could handle both single and multiple files creating just the one archive with all the dropped files contained.
How do you want the archive name generated in case of several files (note that the order in which they're passed to the script by Explorer is random)?
I guess it would make sense to use the short date and time for the file name if possible.
Let me rephrase: if only one file is dropped, generating the archive name is obvious.
But if several files are selected in Explorer and then dropped on the batch file, the order in which they appear as arguments in the batch file is random. in this case, do you have any preference which of the files (alphabetically first one?) should be the basis for the new file name, or do you rather want a generic hard-coded name like "MultiFile-Archive.zip"?
Hey oBdA

I was thinking the name of the archive file could be based on the current time and date at the time the archive was created if that is possible?

Many thanks,
G
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is a stunning solution many thanks!