VBScript
VBScript
Unzip Selected Files from a Zip Archive
See more Zip Examples
Demonstrates how to iterate over the files contained within a .zip and unzip specific files.Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
set zip = CreateObject("Chilkat.Zip")
success = zip.OpenZip("my_files.zip")
If (success = 0) Then
outFile.WriteLine(zip.LastErrorText)
WScript.Quit
End If
unzipDir = "/temp/unzipDir"
' Get the number of files and directories in the .zip
n = zip.NumEntries
set entry = CreateObject("Chilkat.ZipEntry")
i = 0
Do While i < n
success = zip.EntryAt(i,entry)
If (entry.IsDirectory = 0) Then
' (the filename may include a path)
outFile.WriteLine(entry.FileName)
' Your application may choose to unzip this entry
' based on the filename.
' If the entry should be unzipped, then call Extract(unzipDir)
success = entry.Extract(unzipDir)
If (success = 0) Then
outFile.WriteLine(entry.LastErrorText)
WScript.Quit
End If
End If
i = i + 1
Loop
outFile.Close