Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active January 11, 2022 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/3d1a4be10e21094fba8e54969909c3d3 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/3d1a4be10e21094fba8e54969909c3d3 to your computer and use it in GitHub Desktop.
Delete Files in a ZIP Archive in C# .NET
// Load the ZIP archive
using (var archive = new Archive("Archives/archive.zip"))
{
// List to keep files to be deleted
List<ArchiveEntry> entriesToDelete = new List<ArchiveEntry>();
// Loop through ZIP entries
foreach(ArchiveEntry entry in archive.Entries)
{
// Add file/folder into list
if(entry.Name.ToLower().Contains("source"))
{
entriesToDelete.Add(entry);
}
}
// Delete all listed entries
foreach(var entry in entriesToDelete)
{
archive.DeleteEntry(entry);
}
// Save updated archive
archive.Save("Archives/updated-archive.zip");
}
// Load the ZIP archive
using (var archive = new Archive("Archives/archive.zip"))
{
// Delete file by its index
archive.DeleteEntry(0);
// Save updated archive
archive.Save("Archives/updated-archive.zip");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment