Solved

WZZIP command line tool

Posted on 2011-03-08
10
1,058 Views
Last Modified: 2013-12-01
HI there. I'm using the WinZip command line tool WZZIP and I'm a batch file noob.

I'm trying to write a batch file to zip folders that are dropped in "c:\For Zip" and place them in "C:\Zipped Folders".
I need to end up with seperate zip files for each of the folders under the "For Zip" directory.

For example, right now I have the following folders:
c:\For Zip\Folder1
c:\For Zip\Folder2
c:\For Zip\Folder3
etc

I need to end up with:
C:\Zipped Folders\Folder1.zip
C:\Zipped Folders\Folder2.zip
C:\Zipped Folders\Folder3.zip
etc

The following creates one single zip file called TEST.Zip in the "ForZip" directory. How can I create the multiple zip files. A loop of some sort?

@echo off
wzzip -p -r "C:\For Zip\test.zip" "C:\Zipped Folders\*.*"      

Any help is appreciated. Thanks.
Justin
0
Comment
Question by:blastmasterJUS1
  • 5
  • 5
10 Comments
 
LVL 53

Expert Comment

by:Bill Prew
ID: 35076669
In a BAT file, should be as simple as this:

@echo off
for /D %%A in ("c:\For Zip\*") do wzzip "C:\Zipped Folders\%%~nA.zip" "%%~A\*.*"

Open in new window

~bp
0
 

Author Comment

by:blastmasterJUS1
ID: 35078613
Thanks Bill! This seemed to only zip the batch file, which was sitting in the "For Zip" folder along with the sub folders (the ones I want to zip).

 I played around with it for a while and the closest I could get was to end up with the correctly named zip files (Folder1.zip, folder2.zip, etc) in the correct destination folder ("Zipped Folders") however, each zip file contained each one of the folders and the batch file, which was in the directory this time as well.

Any suggestions?

@echo off
for /D %%A in ("C:\FOR ZIP\*") do wzzip -p -r "C:\ZIPPED FOLDERS\%%~nA.zip"

Thanks again.
Justin
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 35082577
Can you make this change to my prior post and tell me what it displays when you run it:

@echo off
for /D %%A in ("c:\For Zip\*") do ECHO wzzip "C:\Zipped Folders\%%~nA.zip" "%%~A\*.*"

~bp
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:blastmasterJUS1
ID: 35083237
Bill, your initial post does indeed work, I didn't see the last part of line 2..my goof!

Anyway, I'm just about there, just one small issue. I ended up with the zip files named correctly (folder1.zip, folder2.zip, etc) andf they contained the correct files and sub folders however, the zip did not include the top level folder (folder1, etc).

i.e.
folder1.zip
contains all of the files and folders under folder1 but I would like folder1 to be zipped so that when I open the zip file I see folder1 sitting in there, and the various files and subfolders would be contained within folder1. Does that make sense?

Thanks again for all of your help!
Justin
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 35084049
Give this a try, not positive if it will give you what you want but I think it should.

@echo off
for /D %%A in ("c:\For Zip\*") do wzzip -P "C:\Zipped Folders\%%~nA.zip" "%%~A\*.*"

Open in new window

~bp
0
 

Author Comment

by:blastmasterJUS1
ID: 35085845
Bill, thanks again for your expertise...that last piece zipped the whole "For Zip" directory into folder1.zip, the same for folder2.zip, and then folder3.zip contained the sub directories of folder3 for some reason...

This line below seems to work best however, I'm still ending up with the contents of Folder1 in the folder1.zip..what I need is Folder1 itself to be zipped along with it's contents. So that , when I open Folder1.zip, I would see Folder1 only (it's contents included within), not the contents of folder1.


@echo off
for /D %%A in ("c:\For QC AND RESCAN\*") do wzzip -p -r "C:\FOR INDEXING\%%~nA.zip" "%%~A\*.*"


Justin

 
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 35089588
Okay, I think I have something that should do what you want.  Give this a try.

@echo off
set FromDir=c:\For QC AND RESCAN
set ToDir=C:\FOR INDEXING
pushd "%FromDir%"
for /D %%A in (*) do (
  "C:\Program Files\WinZip\WZZIP.EXE" -P -r "%ToDir%\%%~nA.zip" "%%~A\*.*"
)
popd

Open in new window

~bp
0
 

Author Closing Comment

by:blastmasterJUS1
ID: 35090056
Thanks for taking the time!
0
 

Author Comment

by:blastmasterJUS1
ID: 35090057
Beautiful!

Thanks again!
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 35090269
Great, glad I was able to help, thanks.

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a common problem that often server suffers from the lack of space on system volume. Old servers or new ones from vendors come with preformatted small volume - 5-6GB in total and after installing updates or applications the free space on system…
A while back when OPSMGR 2012 was released we were very excited about getting it into our environment and upgrading our 2007 implementation,  we started our planning and we then proceeded with our implementation. All went as planned & our system …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question