Mono SharpZipLib';s FastZip没有';t解压缩Mac上的目录

Mono SharpZipLib';s FastZip没有';t解压缩Mac上的目录,mono,sharpziplib,fastzip,Mono,Sharpziplib,Fastzip,我在Mac上使用以下代码,使用Mono解压zip文件。zip文件包含目录下的条目(例如foo/bar.txt)。但是,在解压后的目录中,FastZip不是用文件bar.txt创建目录foo,而是创建一个文件foo\bar.txt。我该怎么做 FastZip fz = new FastZip(); string filePath = @"path\to\myfile.zip"; fz.ExtractZip(filePath, @"path\to\unzip\to", null); 这会在pat

我在Mac上使用以下代码,使用Mono解压zip文件。zip文件包含目录下的条目(例如
foo/bar.txt
)。但是,在解压后的目录中,FastZip不是用文件
bar.txt
创建目录
foo
,而是创建一个文件
foo\bar.txt
。我该怎么做

FastZip fz = new FastZip();
string filePath = @"path\to\myfile.zip";

fz.ExtractZip(filePath, @"path\to\unzip\to", null);

这会在
path\to\unzip\to
中创建一个文件
foo\bar.txt
,显然无法在这种情况下使用
FastZip
,因此我最终编写了自己的解压缩机制:

string filePath = @"path\to\myfile.zip";
string unzipDir = @"path\to\unzip\to";

using (var zipFile = new ZipFile(filePath))
{
    foreach (var zipEntry in zipFile.OfType<ZipEntry>())
    {
        var unzipPath = Path.Combine(unzipDir, zipEntry.Name);
        var directoryPath = Path.GetDirectoryName(unzipPath);

        // create directory if needed
        if (directoryPath.Length > 0)
        {
            Directory.CreateDirectory(directoryPath);
        }

        // unzip the file
        var zipStream = zipFile.GetInputStream(zipEntry);
        var buffer = new byte[4096];

        using (var unzippedFileStream = File.Create(unzipPath))
        {
            StreamUtils.Copy(zipStream, unzippedFileStream, buffer);
        }
    }
}
stringfilepath=@“path\to\myfile.zip”;
字符串unzipDir=@“path\to\unzip\to”;
使用(var zipFile=new zipFile(filePath))
{
foreach(zipFile.OfType()中的变量zipEntry)
{
var unzipPath=Path.Combine(unzipDir,zipEntry.Name);
var directoryPath=Path.GetDirectoryName(解压路径);
//如果需要,创建目录
如果(directoryPath.Length>0)
{
CreateDirectory(directoryPath);
}
//解压缩文件
var zipStream=zipFile.GetInputStream(zipEntry);
var buffer=新字节[4096];
使用(var unzippedFileStream=File.Create(unzipPath))
{
Copy(zipStream、解压缩文件流、缓冲区);
}
}
}

创建zip时使用正斜杠分隔文件夹

我们不控制zip的创建。您不需要为此降低我的级别。。。它可以帮助控制zip文件的其他人。