ZipEntry 内部有一个公共函数可以为您清除名称。“ZipEntry.CleanName(你的字符串)”。当您同时添加条目并尝试删除它时进行此调用。注意:如果您将其用于文件路径,即使 CleanName 函数将“\”替换为“/”,它也会正确解释 zip 文件中的路径
**
添加 ZIPENTRY
**
zipEntryKey = file.FullName.Replace(file.Directory.Root.ToString(), string.Empty);
zipEntryKey = ZipEntry.CleanName(zipEntryKey);
ZipEntry entry = new ZipEntry(zipEntryKey);
entry.DateTime = file.LastWriteTime;
Stream fileStream = Minify(file);
byte[] buffer = new byte[fileStream.Length];
entry.Size = fileStream.Length;
fileStream.Read(buffer, 0, buffer.Length);
fileStream.Close();
zipStream.PutNextEntry(entry);
zipStream.Write(buffer, 0, buffer.Length);
zipStream.CloseEntry();
删除 ZIPENTRY
zipEntryKey = file.FullName.Replace(file.Directory.Root.ToString(), string.Empty);
zipEntryKey = ZipEntry.CleanName(zipEntryKey);
if (existingZip.FindEntry(zipEntryKey, true) > -1)
{
existingZip.BeginUpdate();
ZipEntry Existing = existingZip[existingZip.FindEntry(zipEntryKey, true)];
existingZip.Delete(Existing);
existingZip.CommitUpdate();
}