![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Remove an Entry from an Existing ZIP Using DeleteEntry
This example demonstrates how to use the The example:
Suppose the original ZIP archive contains:
After deleting
The entry is removed only from the in-memory ZIP object until a
Note: This example requires Chilkat v11.0.0 or greater.
IncludeFile "CkZip.pb" IncludeFile "CkZipEntry.pb" Procedure ChilkatExample() success.i = 0 success = 0 ; ------------------------------------------------------------ ; First create a ZIP archive containing three text files. zip.i = CkZip::ckCreate() If zip.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkZip::ckNewZip(zip,"original.zip") If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf charset.s = "utf-8" success = CkZip::ckAddString(zip,"a.txt","Contents of file A",charset) If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf success = CkZip::ckAddString(zip,"b.txt","Contents of file B",charset) If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf success = CkZip::ckAddString(zip,"c.txt","Contents of file C",charset) If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Write the ZIP archive to disk. ; ; The ZIP now contains: ; ; a.txt ; b.txt ; c.txt ; success = CkZip::ckWriteZipAndClose(zip) If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; ------------------------------------------------------------ ; Open the existing ZIP archive for modification. zip2.i = CkZip::ckCreate() If zip2.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkZip::ckOpenZip(zip2,"original.zip") If success = 0 Debug CkZip::ckLastErrorText(zip2) CkZip::ckDispose(zip) CkZip::ckDispose(zip2) ProcedureReturn EndIf ; Find the entry named "b.txt". entry.i = CkZipEntry::ckCreate() If entry.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkZip::ckEntryOf(zip2,"b.txt",entry) If success = 0 Debug CkZip::ckLastErrorText(zip2) CkZip::ckDispose(zip) CkZip::ckDispose(zip2) CkZipEntry::ckDispose(entry) ProcedureReturn EndIf ; Remove the entry from the in-memory ZIP object. ; ; At this point, the original ZIP file on disk is unchanged. ; The deletion takes effect only after WriteZip or ; WriteZipAndClose is called. success = CkZip::ckDeleteEntry(zip2,entry) If success = 0 Debug CkZip::ckLastErrorText(zip2) CkZip::ckDispose(zip) CkZip::ckDispose(zip2) CkZipEntry::ckDispose(entry) ProcedureReturn EndIf ; Write the modified ZIP archive to a new file. CkZip::setCkFileName(zip2, "modified.zip") success = CkZip::ckWriteZipAndClose(zip2) If success = 0 Debug CkZip::ckLastErrorText(zip2) CkZip::ckDispose(zip) CkZip::ckDispose(zip2) CkZipEntry::ckDispose(entry) ProcedureReturn EndIf ; The modified ZIP now contains: ; ; a.txt ; c.txt ; Debug "ZIP archive updated successfully." CkZip::ckDispose(zip) CkZip::ckDispose(zip2) CkZipEntry::ckDispose(entry) ProcedureReturn EndProcedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.