Zip folders in directory with password

Gucci_Rey
Gucci_Rey used Ask the Experts™
on
I would like to zip all folders with a password in a specific directory.

Example :

Only the folders that are not yet zipped with the current folder name should be zipped.

c:\temp\Folder1 -> contains still files
c:\temp\Folder2-> contains still files
c:\temp\Folder3-> contains still files
c:\temp\Folder4.zip -> folder is zipped with password already , ignore this folder
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
MaheshArchitect
Distinguished Expert 2018

Commented:
This is not possible without 3rd party tools

Also tools won't create separate archiver for every folder underneath

U need to do this manually

Author

Commented:
I dont agree...
MaheshArchitect
Distinguished Expert 2018

Commented:
this is not possible unless somebody write code / script to traverse each folder and zip it with password for you (that also with some 3rd party software like winzip, WinRAR or 7zip etc)
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
What you could do is change to that folder and create a list of non zipped folders, something like this:

c:
cd \temp
dir /a:d <folder name pattern>

Can you try the above to get the list only containing Folder1 Folder2 and Folder3?

If so then you could use a for loop with this list and zip each folder using: 7z a <variable>.zip <variable> -pSECRET

When the archive is created correctly (check) then you can add a command to delete the 'source' folder (7z doesn't support a move command).
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Do you have 7zip or some other zip utility installed?  If not, can you install 7zip, and then we can create a BAT script to do what you want using it.

~bp

Author

Commented:
I can install 7zip, I have cirrently winzip installed

Author

Commented:
This is basically what I am currently doing from my side :

The problem is, in Folder 1 there could be more then one folder.

Each folder should be zipped with it's folder name.

Already zipped folders should be ignored.


cd C:\Temp

set /p PASS="PASSWORD"

set WZZIPPY="C:\Program Files (x86)\WinZip\wzzip.exe"

c:
cd c:\temp\Folder1\                                 
%WZZIPPY% -m %PASS% Archive_%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%.zip *.txt

Open in new window

IT / Software Engineering Consultant
Top Expert 2016
Commented:
Based on your explanations so far this feels like it should be what you described.  It looks for all folders in the starting folder, and if there isn't a zip file already with that folder name it will zip that folder.

@echo off
setlocal

rem Define base folder and path to command line zip utility
set BaseDir=c:\temp\Folder1
set wzzip=C:\Program Files (x86)\WinZip\wzzip.exe

rem Prompt for password, if not entered exit
set Pass=
set /p Pass="Password:"
if "%Pass%" EQU "" exit /b

rem Change to desired base folder, if unsuccessful exit
pushd "%BaseDir%"
if /i "%CD%" NEQ "%BaseDir%" exit /b

rem Loop over first level folders in base folder
for /d %%A in (*.*) do (

  rem Only zip files if not already a zip with this folder name
  if not exist "%%~A.zip" (

    rem Zip first level files in this folder
    "%wzzip%" -s%Pass% "%%~A.zip" *.*

  )

)

rem Return to current folder when script started
popd

Open in new window

~bp
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Did you try my last solution?

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial