在c#中检查zip是否为空

Big*_*nne 0 c# asp.net

我有个问题。我试图查明我的 .zip 文件是否为空。问题是测试长度不起作用,因为 zip 文件的大小永远不会等于 0。

FileInfo[] fileInfos = ...
foreach (FileInfo fileInfo in fileInfos)
{                    
    if (fileInfo.Length < 0)
    {
       //  do action like delete
    }                                 
}
Run Code Online (Sandbox Code Playgroud)

预先感谢您的帮助

mxm*_*ile 5

您可以使用ZipArchive功能:

using System.IO.Compression;

using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Read))
{
  int fileCount = archive.Entries.Count;
  bool isEmpty = fileCount == 0;
}
Run Code Online (Sandbox Code Playgroud)