从ZipFile中检索文件名

时间:2017-08-10 19:39:05

标签: c# zipfile ionic-zip

就像标题所说,我需要从zip文件中读取文件的名称。我打算将名字输入2D字符串数组(以及其他数据)。这是我想要做的一个开始的例子。

private String[,] ArrayFiller(ZipFile MyZip)
{
    int count = 0;
    ZipFile zipfile = ZipFile.Read();
    int zipSize = MyZip.Count;
    string[,] MyArr = new string[zipSize, zipSize];

    foreach (ZipEntry e in zipfile.EntriesSorted)
    {
        //otherArr[count,count] = e; -adds the file, but I need title
    }
    return MyArr;
}

我确定我遗漏了一些简单的东西,但我似乎无法在ZipFile类中找到“文件名”属性。导入的包称为Ionic.Zip。

也许它是某种拉链物体的属性?

2 个答案:

答案 0 :(得分:3)

您需要使用ZipArchive类。来自MSDN

    using (ZipArchive archive = ZipFile.OpenRead(zipPath))
    {
        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            Console.WriteLine(entry.FullName);
            //entry.ExtractToFile(Path.Combine(destFolder, entry.FullName));
        }
    } 

答案 1 :(得分:3)

ZipArchive课可能会更幸运。

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
          // The file name is entry.FullName
     }
}