题
我已经四处寻找示例,但似乎找不到涉及提取某个文件夹的Dotnetzip方案。我正在尝试从.zip文件中提取一个名为“ CSS”的文件夹,并且它是.zip文件中的顶级文件夹。这是我到目前为止的代码:
using (ZipFile zip1 = ZipFile.Read(savedFileName))
{
var selection = from e in zip1.Entries
where System.IO.Path.GetFileName(e.FileName).StartsWith("CSS/")
select e;
foreach (var e in selection)
e.Extract(_contentFolder);
}
当前的选择什么也没抓住,我可以使用一些帮助重写,以便提取CSS文件夹及其所有子目录和文件。
解决方案
这对我有用。
public void ExtractFiles(string fileName, string outputDirectory)
{
using (ZipFile zip1 = ZipFile.Read(fileName))
{
var selection = (from e in zip1.Entries
where (e.FileName).StartsWith("CSS/")
select e);
Directory.CreateDirectory(outputDirectory);
foreach (var e in selection)
{
e.Extract(outputDirectory);
}
}
}
其他提示
尝试这个:
var entries = zip.SelectEntries("*", @"folder1\folder2\");
foreach (var file in entries)
{/* extract here */}
我认为这是最好的方法。
不隶属于 StackOverflow