我将使用 sevenzipsharp 从 iso 文件中提取文件到 usb。为此,我从 vs nuget 包管理器下载了 sevenzipsharp,我编码(实际上我无法:))这段代码。我没有接受任何错误,但它不起作用。我在哪里犯错误?请写下细节。
if (IntPtr.Size == 8) //x64
{
SevenZip.SevenZipExtractor.SetLibraryPath(@"C:Program Files7-Zip7z.dll");
}
else //x86
{
SevenZip.SevenZipCompressor.SetLibraryPath(@"C:Program Files (x86)7-Zip7z.dll");
}
using (var file = new SevenZipExtractor(sourcePath))
{
file.ExtractArchive(outputPath);
}
提前谢谢你
对于x86,您正在做您可能打算做SevenZip.SevenZipExtractor.SetLibraryPath
SevenZip.SevenZipCompressor.SetLibraryPath
。
class Program
{
const string zipFile = @"D:downloadsprice.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();
//...
}
}
}
}
}
}