【问题标题】:how to basically extract file with sevenzipsharp如何基本上用sevenzipsharp提取文件
【发布时间】:2015-01-31 20:50:32
【问题描述】:

我将使用sevenzipsharp 从iso 文件中提取文件到usb。为此,我从 vs nuget 包管理器下载了sevenzipsharp,并编写了代码(实际上我不能:))这段代码。我没有任何错误,但它不起作用。我在哪里犯错?请写详细信息。

if (IntPtr.Size == 8) //x64
{
    SevenZip.SevenZipExtractor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
}
else //x86
{
    SevenZip.SevenZipCompressor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
}
using (var file = new SevenZipExtractor(sourcePath))
{
    file.ExtractArchive(outputPath);  
}

提前谢谢你

【问题讨论】:

  • 你能编辑你的答案并更具体吗?您收到什么错误消息?
  • 我编辑了问题,感谢您的关注
  • 即使在编辑之后,也不清楚您的问题是什么。 "I dont take any error. Where do I make mistakes? Please write details." 从任何角度看都是零意义。
  • 再次嗨 亲爱的 B.K 我也对此感到不舒服,但我不知道为什么它不起作用,我也不知道我可以与你分享什么,因为它没有返回任何结果、错误或其他东西.我只是想用c#将一个iso文件解压到目录中,你们能帮我吗?
  • @HaydarŞAHİN 我将逐步检查代码并确保sourcePathoutputPath 不为空。我还将确保您将 SevenZip 库路径设置为实际存在的路径。如果您在 x64 上运行并期望它的 int 指针大小为 8,请确保您正在为 x64 或任何 CPU 构建。

标签: c# extract sevenzipsharp


【解决方案1】:

对于 x86,您正在执行 SevenZip.SevenZipCompressor.SetLibraryPath,而您可能打算执行 SevenZip.SevenZipExtractor.SetLibraryPath

【讨论】:

    【解决方案2】:
    class Program
    {
        const string zipFile = @"D:\downloads\price.zip";
    
        static void Main(string[] args)
        {
            using (Stream stream = File.OpenRead(zipFile))
            {
                string dllPath = Environment.Is64BitProcess ?
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7z64.dll")
                        : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7z.dll");
    
                SevenZipBase.SetLibraryPath(dllPath);
    
                Extract(stream);
            }
        }
    
        static void Extract(Stream archiveStream)
        {
            using (SevenZipExtractor extr = new SevenZipExtractor(archiveStream))
            {
                foreach (ArchiveFileInfo archiveFileInfo in extr.ArchiveFileData)
                {
                    if (!archiveFileInfo.IsDirectory)
                    {
                        using (var mem = new MemoryStream())
                        {
                            extr.ExtractFile(archiveFileInfo.Index, mem);
    
                            string shortFileName = Path.GetFileName(archiveFileInfo.FileName);
                            byte[] content = mem.ToArray();
                            //...
                        }
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      • 2016-05-02
      相关资源
      最近更新 更多