如何删除 .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();
}
关于c# - 如何使用 .NET 删除 Zip 文件中的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9855155/