简体   繁体   English

C#使用7zip获取存档中的文件列表?

[英]C# Using 7zip to get list of files in an archive?

I am using 7zip http://www.7-zip.org/download.html in a C# program to unzip files using the code below. 我在C#程序中使用7zip http://www.7-zip.org/download.html使用下面的代码解压缩文件。

Process t = new Process();
t.StartInfo.FileName = "7za.exe";
t.StartInfo.Arguments = "e " + filePath[i] + " -y -o" + directory[3];
t.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
t.EnableRaisingEvents = true;
t.StartInfo.UseShellExecute = false;
l.StartInfo.RedirectStandardOutput = true;
t.Start();
Console.WriteLine(l.StandardOutput.ReadToEnd());
t.WaitForExit();

I have found searching through the 7zip help that it is possible to use l instead of e (line 3) to list the contents of the archive, but I can't figure out how to get the file names of the files contained in the archive. 我发现在7zip帮助中搜索可以使用l而不是e(第3行)来列出存档的内容,但我无法弄清楚如何获取存档中包含的文件的文件名。 Any ideas? 有任何想法吗? Thanks! 谢谢!

You should use the 7zip SDK or SevenZipSharp . 您应该使用7zip SDKSevenZipSharp

To answer your question, set RedirectStandardOutput to true, then read t.Output . 要回答您的问题,请将RedirectStandardOutput设置为true,然后读取t.Output

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

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