Solved

WZZIP command line tool

Posted on 2011-03-08
10
1,046 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 52

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 52

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
 

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 52

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
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.

 

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 52

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 52

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
In this article we have discussed the manual scenarios to recover data from Windows 10 through some backup and recovery tools which are offered by it.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now