从里面的ZipFile检索文件名

问题描述 投票:1回答:2

就像标题所说,我需要从一个zip文件中读取文件的名称。我要去的名字送入一个二维字符串数组(连同其他数据)。下面是想我做开头的例子。

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

我敢肯定,我失去了一些东西简单,但我似乎无法找到zip文件类中的“文件名”属性。导入包名为Ionic.Zip。

也许是某种压缩对象的属性?

c# zipfile ionic-zip
2个回答
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));
        }
    } 

3
投票

你可能有更多的运气与ZipArchive类。

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
          // The file name is entry.FullName
     }
} 
© www.soinside.com 2019 - 2024. All rights reserved.