Solved

WZZIP command line tool

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

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:blastmasterJUS1
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 250 total points
Comment Utility
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
Comment Utility
Thanks for taking the time!
0
 

Author Comment

by:blastmasterJUS1
Comment Utility
Beautiful!

Thanks again!
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Great, glad I was able to help, thanks.

~bp
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

10 Experts available now in Live!

Get 1:1 Help Now