Batch compressing many subfolders "reborn" - Is there a correct vbs script ?

When we have a folder with a lot of compressed files to uncompress (zip, rar, ace, others) we can use a good program such as WinRar, that integrates in context menu, and offers the option "Extract each archive to separate folder". This is a great thing because we do not need to uncompress each file separately (one after other), what would be very, very boring and time-consuming ! My question is the inverse - I have a main folder with a lot of subfolders and I want to "Compress each folder to separate archive" (make a compressed file for each subfolder, and keeping the sub-sub-folder structure, in a automatic batch). For example C:> A\A1 and C:> A\A2 are the 2 main subfolders (A1 and A2, inside A); A1 and A2 have a lot of sub-sub-folders that does not matter to enumerate; and I want to create A1.zip and A2.zip by one only action (rather than compress each one separately... 2 are just 2 but imagine what would be 80!!...).
If you look at http://www.experts-exchange.com/Miscellaneous/Q_21798037.html you will see that I have posted this question in a different section (Miscellaneous) and acsell tried to make a vbs script using WinRar or 7-Zip. Unhappily acsell could not make a correct vbs script. I would like someone to make it because I am beginning to learn Visual Basic Script (I am a novice/beginner/newbie), so I would like to see the correct code as a good way to learn VBS.
asgarcymedAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

vinnyd79Commented:
If you have a non shareware version of winzip you could use something like this:

Dim Wshell,fso,fldr,fld
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wshell = CreateObject("Wscript.Shell")
Set fldr = fso.GetFolder("C:\tmp")

For each fld in fldr.SubFolders
   ' zip the folder & all subfolders
   Wshell.Run "winzip -min -a -r -p " & fld.Path & ".zip " & fld
Next


Set Wshell = Nothing
Set fld = Nothing
Set fldr = Nothing
Set fso = Nothing


The above example will go through the C:\tmp dir and zip any folders it finds in that dir to a file with the same name. The zip files will contain each folders subfolders with path info.
asgarcymedAuthor Commented:
vinnyd79 - your vbs script seems to be good but there is a problem - when each folder's name has no spaces (ex : aa.bb.cc\ or aa-bb-cc\ or aa_bb_cc\) your script works perfectly; however, when folders' name have one space (ex : aa bb cc\) it appear a winzip's box message (window) saying "Error : No files were found for this operation - Nothing to do". Can you please debug this ?
vinnyd79Commented:
Try this:

Dim Wshell,fso,fldr,fld
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wshell = CreateObject("Wscript.Shell")
Set fldr = fso.GetFolder("C:\tmp")

For each fld in fldr.SubFolders
   ' zip the folder & all subfolders
   Wshell.Run "winzip -min -a -r -p " & Chr(34) & fld.Path & ".zip" & Chr(34) & " " & fld
Next


Set Wshell = Nothing
Set fld = Nothing
Set fldr = Nothing
Set fso = Nothing

vinnyd79Commented:
Oops, forgot to enclose the foldername in qoutes as well. Try this one instead:


Dim Wshell,fso,fldr,fld
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wshell = CreateObject("Wscript.Shell")
Set fldr = fso.GetFolder("C:\tmp")

For each fld in fldr.SubFolders
   ' zip the folder & all subfolders
   Wshell.Run "winzip -min -a -r -p " & Chr(34) & fld.Path & ".zip" & Chr(34) & " " & Chr(34) & fld & Chr(34)
Next


Set Wshell = Nothing
Set fld = Nothing
Set fldr = Nothing
Set fso = Nothing

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
asgarcymedAuthor Commented:
vinnyd79  - the last vbs script you posted works perfectly - thank you a lot !
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
Visual Basic Classic

From novice to tech pro — start learning today.