Ionic Zip Library v1.9.1.6
RemoveEntry Method (entry)
Removes the given ZipEntry from the zip archive.
Declaration Syntax
Parameters
- entry (ZipEntry)
- The ZipEntry to remove from the zip.
Remarks
After calling RemoveEntry, the application must call Save to make the changes permanent.
Examples
In this example, all entries in the zip archive dating from before
December 31st, 2007, are removed from the archive. This is actually much
easier if you use the RemoveSelectedEntries method. But I needed an
example for RemoveEntry, so here it is.
CopyC#
String ZipFileToRead = "ArchiveToModify.zip"; System.DateTime Threshold = new System.DateTime(2007,12,31); using (ZipFile zip = ZipFile.Read(ZipFileToRead)) { var EntriesToRemove = new System.Collections.Generic.List<ZipEntry>(); foreach (ZipEntry e in zip) { if (e.LastModified < Threshold) { // We cannot remove the entry from the list, within the context of // an enumeration of said list. // So we add the doomed entry to a list to be removed later. EntriesToRemove.Add(e); } } // actually remove the doomed entries. foreach (ZipEntry zombie in EntriesToRemove) zip.RemoveEntry(zombie); zip.Comment= String.Format("This zip archive was updated at {0}.", System.DateTime.Now.ToString("G")); // save with a different name zip.Save("Archive-Updated.zip"); }
CopyVB.NET
Dim ZipFileToRead As String = "ArchiveToModify.zip" Dim Threshold As New DateTime(2007, 12, 31) Using zip As ZipFile = ZipFile.Read(ZipFileToRead) Dim EntriesToRemove As New System.Collections.Generic.List(Of ZipEntry) Dim e As ZipEntry For Each e In zip If (e.LastModified < Threshold) Then ' We cannot remove the entry from the list, within the context of ' an enumeration of said list. ' So we add the doomed entry to a list to be removed later. EntriesToRemove.Add(e) End If Next ' actually remove the doomed entries. Dim zombie As ZipEntry For Each zombie In EntriesToRemove zip.RemoveEntry(zombie) Next zip.Comment = String.Format("This zip archive was updated at {0}.", DateTime.Now.ToString("G")) 'save as a different name zip.Save("Archive-Updated.zip") End Using
Exceptions
Exception | Condition |
---|---|
ArgumentException |
Thrown if the specified ZipEntry does not exist in the ZipFile.
|
See Also