• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 583
  • Last Modified:

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.
0
asgarcymed
Asked:
asgarcymed
  • 3
  • 2
1 Solution
 
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.
0
 
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 ?
0
 
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

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now