我有个问题。我试图查明我的 .zip 文件是否为空。问题是测试长度不起作用,因为 zip 文件的大小永远不会等于 0。
FileInfo[] fileInfos = ...
foreach (FileInfo fileInfo in fileInfos)
{
if (fileInfo.Length < 0)
{
// do action like delete
}
}
Run Code Online (Sandbox Code Playgroud)
预先感谢您的帮助
您可以使用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)
| 归档时间: |
|
| 查看次数: |
433 次 |
| 最近记录: |