views:

2463

answers:

2

I want to unzip a .zip file using VBScript, only it's always a new computer with no external applications on it. Now I know Windows XP and 2003 have an internal .zip folder option, so I guess I can use it via VBScript in order to extract the file.

How do I do it?

I tried:

Set objShell = CreateObject("Shell.Application")

Set SrcFldr = objShell.NameSpace(fileName)
Set DestFldr = objShell.NameSpace(appDir)
DestFldr.CopyHere(SrcFldr) 

Which didn't work. What could be the problem?

+2  A: 

Have a look at the 3rd entry on Rob van der Woude's site.

boost
+5  A: 

Just set ZipFile = The location of the zip file, and ExtractTo = to the location the zip file should be extraced to.


'The location of the zip file.
ZipFile="C:\Test.Zip"
'The folder the contents should be extracted to.
ExtractTo="C:\Test\"

'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
   fso.CreateFolder(ExtractTo)
End If

'Extract the contants of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing
Tester101