(VBScript) Unzip Text File to String
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Zip")
set zip = CreateObject("Chilkat.Zip")
success = zip.OpenZip("qa_data/zips/EC16100.zip")
If (success <> 1) Then
outFile.WriteLine(zip.LastErrorText)
WScript.Quit
End If
' Get the 1st file in the .zip
' entry is a Chilkat.ZipEntry
Set entry = zip.GetEntryByIndex(0)
If (zip.LastMethodSuccess <> 1) Then
outFile.WriteLine("No files in this zip.")
WScript.Quit
End If
fileContents = entry.UnzipToString(0,"utf-8")
outFile.WriteLine(fileContents)
outFile.Close
|