【问题标题】:Retrieve file names from inside ZipFile从 ZipFile 中检索文件名
【发布时间】:2018-01-19 04:55:50
【问题描述】:

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

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

【问题讨论】:

  • 是的,那肯定是错误的文档。
  • @hvd 哎呀。我会更新的。

标签: c# zipfile ionic-zip


【解决方案1】:

您需要使用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));
        }
    } 

【讨论】:

  • 看来您正在将 ZipFile 对象转换为 ZipArchive?保留我所拥有的并将其转换为 ZipArchive 并在文件“条目”上使用 .FullName 方法?
【解决方案2】:

ZipArchive 课程可能会让您更幸运。

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

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2021-12-31
    • 2016-04-08
    • 1970-01-01
    相关资源
    最近更新 更多