![]() |
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
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoZip String sCharset Handle hoZip2 Variant vEntry Handle hoEntry String sTemp1 Move False To iSuccess Move False To iSuccess // ------------------------------------------------------------ // First create a ZIP archive containing three text files. Get Create (RefClass(cComChilkatZip)) To hoZip If (Not(IsComObjectCreated(hoZip))) Begin Send CreateComObject of hoZip End Get ComNewZip Of hoZip "original.zip" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Procedure_Return End Move "utf-8" To sCharset Get ComAddString Of hoZip "a.txt" "Contents of file A" sCharset To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Procedure_Return End Get ComAddString Of hoZip "b.txt" "Contents of file B" sCharset To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Procedure_Return End Get ComAddString Of hoZip "c.txt" "Contents of file C" sCharset To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Procedure_Return End // Write the ZIP archive to disk. // // The ZIP now contains: // // a.txt // b.txt // c.txt // Get ComWriteZipAndClose Of hoZip To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Procedure_Return End // ------------------------------------------------------------ // Open the existing ZIP archive for modification. Get Create (RefClass(cComChilkatZip)) To hoZip2 If (Not(IsComObjectCreated(hoZip2))) Begin Send CreateComObject of hoZip2 End Get ComOpenZip Of hoZip2 "original.zip" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip2 To sTemp1 Showln sTemp1 Procedure_Return End // Find the entry named "b.txt". Get Create (RefClass(cComChilkatZipEntry)) To hoEntry If (Not(IsComObjectCreated(hoEntry))) Begin Send CreateComObject of hoEntry End Get pvComObject of hoEntry to vEntry Get ComEntryOf Of hoZip2 "b.txt" vEntry To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip2 To sTemp1 Showln sTemp1 Procedure_Return End // 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. Get pvComObject of hoEntry to vEntry Get ComDeleteEntry Of hoZip2 vEntry To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip2 To sTemp1 Showln sTemp1 Procedure_Return End // Write the modified ZIP archive to a new file. Set ComFileName Of hoZip2 To "modified.zip" Get ComWriteZipAndClose Of hoZip2 To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoZip2 To sTemp1 Showln sTemp1 Procedure_Return End // The modified ZIP now contains: // // a.txt // c.txt // Showln "ZIP archive updated successfully." End_Procedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.