c# - 如何使用 .NET 删除 Zip 文件中的目录?

标签 c# dotnetzip

如何删除 .zip 中的目录及其中的所有文件(最好使用 DotNetZip)?

现在我正在运行 zip 中的所有文件,但它不起作用:

foreach (ZipEntry e in zip)
{
    //If the file is in the directory I want to delete
    if(e.FileName.Substring(0, 9) == "FolderName/")
    {
        zip.RemoveEntry(e.FileName);                          
    }
}

是否有更好的方法,如果没有,我将如何进行这项工作?

最佳答案

这里有一个简单的方法来做到这一点:

using (ZipFile zip = ZipFile.Read(@"C:\path\to\MyZipFile.zip"))
{
    zip.RemoveSelectedEntries("foldername/*"); // Delete folder and its contents
    zip.Save();
}

文档在这里 http://dotnetzip.herobo.com/DNZHelp/Index.html

关于c# - 如何使用 .NET 删除 Zip 文件中的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9855155/

相关文章:

c# - 如何以编程方式将 XmlNode 添加到 XmlNodeList

c# - C# 中的链接二维矩阵

asp.net-mvc - 在 MVC 中使用内存流和 DotNetZip 给出 "Cannot access a closed Stream"

c# - DotNetZip 从 MemoryStream 打开 zip 文件

c# - 创建并流式传输图像存档 zip 文件以供下载 C#

c# - 如何发出带有预加载 MethodInfo 局部变量的方法?

c# - 休眠 : read write list of string

c# - 使用 XMLWorker 将 HTML 解析为 PDF 时设置行间距 - ITextSharp C#

c# - 以编程方式从 zip 文件中删除已知密码

c# - 通过 DotNetZip 库以编程方式提取 ZIP 文件?