Zip folders in directory with password

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
Gucci_ReyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MaheshArchitectCommented:
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
0
Gucci_ReyAuthor Commented:
I dont agree...
0
MaheshArchitectCommented:
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)
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

Gerwin Jansen, EE MVETopic Advisor 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).
0
Bill PrewCommented:
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
1
Gucci_ReyAuthor Commented:
I can install 7zip, I have cirrently winzip installed
0
Gucci_ReyAuthor 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

0
Bill PrewCommented:
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
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewCommented:
Did you try my last solution?

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.