Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WZZIP command line tool

Posted on 2011-03-08
10
Medium Priority
?
1,100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 57

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 57

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 57

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 57

Accepted Solution

by:
Bill Prew earned 1000 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 57

Expert Comment

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

~bp
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

670 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