在项目中添加引用
System.IO.Compression
System.IO.Compression.FileSystem
判断文件夹是否存在
string zipPath = "H:\\测试.zip";
string upgradePackagePath = "测试文件夹/";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
//如果找到测试文件夹返回名称,没有找到返回null
return archive.GetEntry(upgradePackagePath) == null ? false : true;
}
//判断文件是否存在
string zipPath = "H:\\测试.zip";
string upgradePackagePath = "测试文件夹/1.txt";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
//如果找到测试文件夹返回名称,没有找到返回null
return archive.GetEntry(upgradePackagePath) == null ? false : true;
}
判断文件夹和文件的区别
ZipArchive.GetEntry 中传入的路径有区别
文件夹:测试文件夹/ 注意最后的反斜杠,如果不带是有问题的
文件:测试文件夹/1.txt 传入具体的文件路径,相对于zip包的路径