1

正如标题所说,我需要从 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;
}

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

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

4

2 回答 2

4

你需要使用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));
        }
    } 
于 2017-08-10T19:45:04.393 回答
3

ZipArchive类可能会让您更幸运。

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
     foreach (ZipArchiveEntry entry in archive.Entries)
     {
          // The file name is entry.FullName
     }
} 
于 2017-08-10T19:48:17.777 回答