C# 如何在c中计算zipfile中的文件数

C# 如何在c中计算zipfile中的文件数,c#,zip,C#,Zip,请告诉我如何计算ZIP文件中的文件数 我需要一个C代码在VisualStudio中完成这项工作。我在谷歌搜索时尝试了很多代码,但出现了一个错误,错误是: 找不到ZIPENTRY/ZIPFILE的命名空间或程序集 有人能告诉我应该包括什么/需要安装什么/给我提供计算文件数量的代码吗 int count; using (ZipFile zip = ZipFile.Read(path)) count = zip.Count; 你可以试试这样的东西 你可以参考 你可以试试这样的东西 如MSDN所述,您

请告诉我如何计算ZIP文件中的文件数

我需要一个C代码在VisualStudio中完成这项工作。我在谷歌搜索时尝试了很多代码,但出现了一个错误,错误是:

找不到ZIPENTRY/ZIPFILE的命名空间或程序集

有人能告诉我应该包括什么/需要安装什么/给我提供计算文件数量的代码吗

int count;
using (ZipFile zip = ZipFile.Read(path))
count = zip.Count;
你可以试试这样的东西

你可以参考

你可以试试这样的东西


如MSDN所述,您可以参考.Net 4.5。您可以使用ZipArchive和ZipFile类:

System.IO.Compression命名空间中的类都位于不同的程序集中 但是System.IO.Compression和System.IO.Compression.FileSystem

因此,您可以在项目中添加对System.IO.Compression和System.IO.Compression.FileSystem程序集的引用,并尝试以下操作:

...
using System.IO.Compression; 
...


  // Number of files within zip archive
  public static int ZipFileCount(String zipFileName) {
    using (ZipArchive archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read)) {
      int count = 0;

      // We count only named (i.e. that are with files) entries
      foreach (var entry in archive.Entries)
        if (!String.IsNullOrEmpty(entry.Name))
          count += 1;

      return count;
    }
  }
另一种可能是使用DotNetZip库,请参阅:


正如MSDN在.Net 4.5中所说,您可以使用ZipArchive和ZipFile类:

System.IO.Compression命名空间中的类都位于不同的程序集中 但是System.IO.Compression和System.IO.Compression.FileSystem

因此,您可以在项目中添加对System.IO.Compression和System.IO.Compression.FileSystem程序集的引用,并尝试以下操作:

...
using System.IO.Compression; 
...


  // Number of files within zip archive
  public static int ZipFileCount(String zipFileName) {
    using (ZipArchive archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read)) {
      int count = 0;

      // We count only named (i.e. that are with files) entries
      foreach (var entry in archive.Entries)
        if (!String.IsNullOrEmpty(entry.Name))
          count += 1;

      return count;
    }
  }
另一种可能是使用DotNetZip库,请参阅:


您必须在项目中添加对System.IO.Compression和System.IO.Compression.FileSystem的引用

using (var archive = System.IO.Compression.ZipFile.Open(filePath, ZipArchiveMode.Read))
{
    var count = archive.Entries.Count(x => !string.IsNullOrWhiteSpace(x.Name));
}

您必须在项目中添加对System.IO.Compression和System.IO.Compression.FileSystem的引用

using (var archive = System.IO.Compression.ZipFile.Open(filePath, ZipArchiveMode.Read))
{
    var count = archive.Entries.Count(x => !string.IsNullOrWhiteSpace(x.Name));
}

请参阅Thank vadmin…我在这里也搜索了,但无法获取此链接请参阅Thank vadmin…我在这里也搜索了,但无法获取此链接可能重复的抱歉,但根据MSDN ZipFile是一个静态类,没有ZipFile zip=。。。你能从答案中得到这个密码吗?如果是这样,请指出并添加关于DotNetZip的部分,这至少会使您的代码有效,关于@DmitryBychenko的注释对不起,但根据MSDN ZipFile是一个静态类,没有ZipFile zip=。。。你能从答案中得到这个密码吗?如果是这样,请指出这一点,并添加关于DotNetZip的部分,这至少会使您的代码对@DmitryBychenko的评论有效