由于 Zip 文件使用 \ 而不是 / 导致的 SharpZipLib 问题
我有一堆旧版拉链,但压缩方式不正确。
文件保存在 zip 中,因此它们是文件夹\文件名而不是文件夹/文件名。
这意味着这样的代码:
using (ZipFile zipFile = new ZipFile(@"zippath.zip"))
{
for (int i = 0; i < zipFile.Count; i++)
{
var entry = zipFile[i];
zipFile.BeginUpdate();
zipFile.Delete(entry);
zipFile.CommitUpdate();
...
正在抛出一个
找不到要删除的条目
这是此处发现的已知问题,但不幸的是我无法控制 zip 的制作方式,而且我需要使用多年的 zip 文件。有没有办法可以在使用之前修复删除语句或修复(在 C# 中)zip 文件?
谢谢!
I have a load of Legacy zips that have been zipped incorrectly.
Files were saved in the zip so they are folder\filename rather than folder/filename.
What that means is code like this:
using (ZipFile zipFile = new ZipFile(@"zippath.zip"))
{
for (int i = 0; i < zipFile.Count; i++)
{
var entry = zipFile[i];
zipFile.BeginUpdate();
zipFile.Delete(entry);
zipFile.CommitUpdate();
...
Is throwing a
Cannot find entry to delete
This is a known problem found here but unfortunately I have no control on how the zips are made and there are years worth of zip files I need to work with. Is there a way I can either fix the delete statement or repair (in C#) the zip file before using it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ZipEntry 内部有一个公共函数可以为您清理名称。 “ZipEntry.CleanName(您的字符串)”。当您添加条目并尝试删除它时,请拨打此电话。 注意:如果您将其用于文件路径,即使 CleanName 函数将“\”替换为“/”,它也会正确解释 zip 文件中的路径
**
**
There is a public function inside of ZipEntry that cleans the name for you. "ZipEntry.CleanName(yourstring)". Make this call when you are both adding your entry AND trying to delete it. note: If you are using this for file paths it will interpret the path correctly in the zip file even though the CleanName function replaces "\" with "/"
**
**
修复似乎位于您自己的链接的底部。一位开发人员写了一篇文章,其中的一些代码只是将
\
字符替换为/
。尝试一下,也许您可以从那里删除该邮政编码条目。It appears that the fix is at the bottom of your own link. One of the developers wrote a post with some code that simply replaced the
\
character with a/
. Try that, and perhaps from there you can then delete the zip entry.