PowerBuilder
PowerBuilder
List Files/Directories in Zip by Index
See more Zip Examples
Demonstrates how to iterate over the files and directories in a zip archive by index.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Zip
integer li_NumEntries
oleobject loo_Entry
integer i
li_Success = 0
// This example assumes 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
li_Success = loo_Zip.OpenZip("qa_data/zips/sample.zip")
if li_Success = 0 then
Write-Debug loo_Zip.LastErrorText
destroy loo_Zip
return
end if
li_NumEntries = loo_Zip.NumEntries
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.ZipEntry")
i = 0
do while i < li_NumEntries
loo_Zip.EntryAt(i,loo_Entry)
// Note: In the ZIP file format, it is not required for a ZIP file to contain explicit directory entries.
// However, explicit directory entries can be included for convenience and compatibility with certain ZIP file processing tools and software.
// An explicit directory entry in a ZIP file is an entry that specifically represents a directory, rather than a file.
// It usually has a directory name with a trailing slash (/) and zero-length content.
if loo_Entry.IsDirectory then
Write-Debug string(i) + ": " + loo_Entry.FileName + " (directory)"
else
Write-Debug string(i) + ": " + loo_Entry.FileName
end if
i = i + 1
loop
// Sample output:
// 0: aaa/ (directory)
// 1: aaa/pigs.json
// 2: bbb/ (directory)
// 3: bbb/base64Cert.txt
// 4: bbb/sub1/ (directory)
// 5: bbb/sub1/brasil_cert.pem
// 6: bbb/sub2/ (directory)
// 7: bbb/sub2/penguins.gif
// 8: bbb/sub2/starfish.jpg
// 9: hamlet.xml
// 10: hello.pdf
loo_Zip.CloseZip()
destroy loo_Zip
destroy loo_Entry