在我的应用程序中,我使用DotNetZip来压缩和解压缩文件.在提取文件之前,我想知道提供的密码是否正确.现在我这样做.
foreach (var sourceFile in sourceFileNames) {
ZipFile file = ZipFile.Read(sourceFile);
foreach (ZipEntry entry in file.Entries) {
if (FileSystem.Exists(conf.Target + entry.FileName)) {
FileSystem.Delete(conf.Target + entry.FileName);
}
if (!string.IsNullOrEmpty(conf.Password)) {
entry.Password = conf.Password;
}
entry.Extract(conf.Target);
}
}
Run Code Online (Sandbox Code Playgroud)
这里'sourceFileNames'包含zip文件列表
如果密码错误或没有提供,那么它会给出错误,但我不想这样做.
我想要做的是首先检查每个zip文件的密码,如果所有zip文件都有正确的密码,那么只提取所有密码.
顺便说一下,有一个静态方法来检查Zip文件的密码:
public static bool Ionic.Zip.ZipFile.CheckZipPassword(
string zipFileName,
string password
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2686 次 |
| 最近记录: |