如何使用dotnetzip检查文件是否存在于zip文件中 [英] How to check whether file exists in zip file using dotnetzip
本文介绍了如何使用dotnetzip检查文件是否存在于zip文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用dotnetzip库创建zip。
I am creating zip using dotnetzip library.
但我不知道如何检查zip中是否存在文件。如果文件存在,那么我将用路径更新文件。
But I don't know how to check if a file exists in the zip. If the file exists then I will update the file with path.
public void makezip(string flname)
{
string fln =flname;
string curFile = @"d:\crs.zip";
if (File.Exists(curFile))
{
ZipFile zipfl = ZipFile.Read(@"D:\crs.zip");
var result = zipfl.Any(entry => entry.FileName.EndsWith(@fln));
if (result == true) {
zipfl.UpdateFile(@fln);
}else{
zipfl.AddFile(@fln);
}
zipfl.Save(@"d:\crs.zip");
}
else
{
try
{
ZipFile zipfl = new ZipFile();
var result = zipfl.Any(entry => entry.FileName.EndsWith(@fln));
if (result == true)
{
zipfl.AddFile(@fln);
}
zipfl.Save(@"d:\crs.zip");
}catch {
MessageBox.Show("Invalid Zip File");
}}}
推荐答案
如何检查zip文件中是否存在文件?
How to check whether file exists in zip file?
只需使用LINQ Any ,假设您输入了zip文件
input.zip
,以检查 input.zip
包含 input.txt
:
Just use LINQ Any
, assume you have input zip file input.zip
, to check whether input.zip
contains input.txt
:
var zipFile = ZipFile.Read(@"C:\input.zip");
var result = zipFile.Any(entry => entry.FileName.EndsWith("input.txt"));
这篇关于如何使用dotnetzip检查文件是否存在于zip文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文