简体   繁体   English

如何基本上用sevenzipsharp提取文件

[英]how to basically extract file with sevenzipsharp

I will extract files to usb from iso file with sevenzipsharp. 我将使用sevenzipsharp从iso文件中提取文件到usb。 For this, I download sevenzipsharp from vs nuget package manager and I coded (actually I couldn't :) ) this code . 为此,我从vs nuget包管理器下载sevenzipsharp,我编码(实际上我不能:))这段代码。 I dont take any error but It isnt working. 我不接受任何错误,但它不工作。 Where do I make mistakes? 我在哪里犯错误? Please write details. 请写详细信息。

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);  
}

Thank you in advance 先感谢您

对于x86,你正在做SevenZip.SevenZipCompressor.SetLibraryPath ,你可能想做SevenZip.SevenZipExtractor.SetLibraryPath

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();
                        //...
                    }
                }
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM