-1

我在使用sharpcompress包在c#中提取rar文件时遇到错误,我在Nunrar、sevenzip提取器和这么多包中尝试过,但面临同样的错误

String filename = @"" + textBox8.Text;
string ppath = @"" + System.IO.Path.GetDirectoryName(textBox8.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(textBox8.Text);
System.IO.Directory.CreateDirectory(@"" + ppath);
try
{
    var archive = SharpCompress.Archives.Rar.RarArchive.Open(filename);
    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
    {
        entry.WriteToDirectory(ppath, new ExtractionOptions()
        {

        });
    }
}
catch(Exception ex)
{
    textBox10.Text = Convert.ToString(ex);
}
4

1 回答 1

0

最后我解决了 NunRar Supports Rar4 format

字符串文件名 = @"" + textBox8.Text; 字符串 ppath = @"" + System.IO.Path.GetDirectoryName(textBox8.Text) + "\" + System.IO.Path.GetFileNameWithoutExtension(textBox8.Text); string ext = textBox7.Text.Substring(textBox7.Text.IndexOf("."));

            try
            {


                if (ext == ".rar")
                {
                    System.IO.Directory.CreateDirectory(@"" + ppath);
                    try
                    {
                        NUnrar.Archive.RarArchive.WriteToDirectory(filename, ppath, NUnrar.Common.ExtractOptions.ExtractFullPath | NUnrar.Common.ExtractOptions.Overwrite);

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);

                    }

                }
                else if (ext == ".zip")
                {
                    System.IO.Directory.CreateDirectory(@"" + ppath);
                    try
                    {
                        ZipFile.ExtractToDirectory(filename, ppath);

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
于 2018-03-15T08:24:18.217 回答