Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to unzip multiple zip folders using VBscript?

Status
Not open for further replies.

travelnitwit

Technical User
Oct 11, 2013
5
US
I need a VB script to unzip multiple different zip folders. I have this script - but it does not work.

Unzip "c:\DailySearch\*.zip", "c:\DailySearch"

Sub Unzip(sSource, sTargetDir)
Set oFSO = CreateObject("Scripting.FileSystemObject")
if not oFSO.FolderExists(sTargetDir) then oFSO.CreateFolder(sTargetDir)
Set oShell = CreateObject("Shell.Application")
Set oSource = oShell.NameSpace(sSource).Items()
Set oTarget = oShell.NameSpace(sTargetDir)
oTarget.CopyHere oSource, 256
End Sub
 
When you say "does not work" could you please be a little more explicit?
 
I get an error :
Line 8 Char 5 Object required: 'oShell.NameSpace(...)'
 
Ok. The problem is that you cannot use a wild card in a filename being passed to the NameSpace method. You'll have to do your own expansion, and pass filenames individually.
 
I tried this:

I don't get any errors but it doesn't do anything either. Can you see anything wrong?

Sub Unzip
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("c:\DailySearch\").Files
If LCase(fso.GetExtensionName(f)) = "zip" Then
Unzip f.path, "c:\DailySearch"
End If
Next
End Sub
 
Odd. Thought I'd already posted an initial response to this.

Ok - before going any further, can you just verify what your Unzip routine is actually doing. In your last example you illustrate an Unzip sub with no parameters which is calling ... an Unzip sub (presumably the original Unzip from your first post) that takes two parameters ...

Get that sorted, and perhaps your code will work. Certainly look like it ought to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top