1

我需要在 C# 中提取一个拆分的 rar 文件 (r00, r01, r02,...)。

我发现唯一可能有用的是sevenzipsharp。我找不到我正在尝试做的事情的例子。

有人说“ https://archive.codeplex.com/?p=sevenzipsharp提供的文档”,但这并没有真正的帮助,因为我在那里找不到任何示例。

我知道如果我使用不同的压缩格式,一切都会容易得多,但我不负责 zip 文件的生成,所以很遗憾这不是一个选择。



* 更新 2019 年 1 月 17 日 *

我试过了:

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            // Toggle between the x86 and x64 bit dll
            var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
            SevenZip.SevenZipBase.SetLibraryPath(path);

            using (var file = new SevenZipExtractor(@"F:\ziptest\test.part1.rar"))
            {
                file.ExtractArchive(@"F:\dav\");
            }
        }
    }
}

但这给了我一个错误,当调用“ExtractArchive”时:

An unhandled exception of type 'SevenZip.SevenZipArchiveException' occurred in SevenZipSharp.dll

Additional information: Invalid archive: open/read error! Is it encrypted and a wrong password was provided?



* 更新 2019 年 1 月 20 日 *

我最终使用了这里提供的解决方案: Unrar an archive in C#

我修改了开关参数,使 WinRar 在后台运行,无需打开任何窗口。

如果有人确实想出了解决我的 SevenZipSharp 问题的方法,我仍然想知道,因为它是一个更“干净”的代码。

4

1 回答 1

0

codeplex 站点有一个讨论论坛,其中显示了几个 github 分支。我关注了这个示例:https ://github.com/squid-box/SevenZipSharp/blob/dev/SevenZip.Tests/SevenZipExtractorTests.cs#L64 ,这表明您只需要将第一卷传递给 SevenZipExtractor 构造函数。

using (var extractor = new SevenZipExtractor(@"TestData\multivolume.part0001.rar")) {
    extractor.ExtractArchive(OutputDirectory);
}
于 2019-01-17T01:19:44.350 回答