Learn how to delete files and folders in ZIP archives in C#: https://blog.aspose.com/2022/01/11/delete-files-in-zip-archive-csharp-net/
Last active
January 11, 2022 16:18
-
-
Save aspose-com-gists/3d1a4be10e21094fba8e54969909c3d3 to your computer and use it in GitHub Desktop.
Delete Files in a ZIP Archive in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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