Developers, Developers, Developers! Maksim Sorokin IT Blog

24May/100

Extracting ZIP Files with VBScript

The following VBScript awaits two parameters -- the source ZIP file and target extract location:

Set args = WScript.Arguments

'The location of the zip file.
ZipFile=args.item(0)
'The folder the contents should be extracted to.
ExtractTo=args.item(1)

'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
Tagged as: , No Comments