Sample code for 30+ languages & platforms
PowerBuilder

Modify Name of File Stored within Zip when Creating a .zip

See more Zip Examples

Demonstrates how to create a zip where the filename within the .zip is different than the filename that was added from the filesystem.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Zip
integer li_SaveExtraPath
oleobject loo_Entry

li_Success = 0

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Zip = create oleobject
li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip")
if li_rc < 0 then
    destroy loo_Zip
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Intialize the zip object by calling NewZip.
li_Success = loo_Zip.NewZip("myZip.zip")

// Add a reference to a file on disk to the zip object.
// (When appending files to a zip, the files are not actually
// read into memory.  References to the file(s) are added.
// When WriteZip is called, the referenced files are streamed in
// and compressed to the .zip.)
li_SaveExtraPath = 0
li_Success = loo_Zip.AddFile("/temp/a/hamlet.xml",li_SaveExtraPath)
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

// The zip object references a single file.
// Retrieve the entry object...
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.ZipEntry")

loo_Zip.EntryAt(0,loo_Entry)

// Set the entry's filename to anything you want:
loo_Entry.FileName = "somethingElse.xml"

// Note: Internally, the zip component retains the name of
// the file referenced.  The current setting of the zip entry's
// FileName property is stored in the .zip when writing.

// The zip written here will contain somethingElse.xml
li_Success = loo_Zip.WriteZipAndClose()
if li_Success <> 1 then
    Write-Debug loo_Zip.LastErrorText
else
    Write-Debug "Zip created!"
end if



destroy loo_Zip
destroy loo_Entry