提取分割的rar文件

时间:2019-01-17 00:20:55

标签: c# rar sevenzipsharp

我需要在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问题的方法,我仍然想知道,因为它是一个更“干净”的代码。

1 个答案:

答案 0 :(得分: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);
}