【问题标题】:unicode in filenames when unzipping in C# [duplicate]在 C# 中解压缩时文件名中的 unicode [重复]
【发布时间】:2013-11-14 13:16:42
【问题描述】:

我有这个使用 .NET 库(压缩)的解压缩功能,但问题是我在文件名中有一些 unicode 问题,例如“µ”正在转换为“æ”

在不使用其他解压缩库的情况下是否有解决此问题的方法,因为我仅限于某些许可证,并且发现这个套件最适合我

 using System.IO.Compression;

 private void Unzip()
    {
        try
        {
            string appPath = Path.GetDirectoryName(Application.ExecutablePath);

            // unzip update
            using (ZipArchive archive = System.IO.Compression.ZipFile.OpenRead(ZipFile))
            {

                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    string fullPath = Path.Combine(appPath, entry.FullName);
                    if (String.IsNullOrEmpty(entry.Name))
                    {
                        Directory.CreateDirectory(fullPath);
                    }
                    else
                    {
                        if (!entry.Name.Equals("Updater.exe"))
                        {
                            entry.ExtractToFile(fullPath,true);

                        }
                    }
                }

                //  UpdateProgress(((float)s.Position / (float)fileStream.Length) * 100F);
                //System.Threading.Thread.Sleep(extraWaitMilliseconds); //don't go too fast

            }
            UnzipFinished();  //*********^

        }            
        catch (Exception ex)
        {
        UnzipFailed(ex);
        }
    }

【问题讨论】:

  • 我喜欢你所说的“这个最适合你”,尽管它显然不适合你(因此这里的问题)。
  • 我喜欢你用你自己的方式解释它。当涉及到我受限的许可问题时,它最适合我。
  • 请注意,GvS 接受的答案并不完全正确。它适用于 zip 文件使用 cp850 的特定情况。如果它使用不同的编码,您将不得不指定它。有关背景信息,请参阅 Adriano 的回答。但根据您的示例,cp850 可能是您的正确选择。

标签: c# .net unicode unzip


【解决方案1】:

我阅读了您对许可证的限制,但我认为,您会发现这篇关于 codeproject 的文章很有用。

它解释了如何使用带有点网包装的 windows 内部 ZIP,并且此链接中的讨论线程帮助我处理文件/目录名称中的特殊字符。

Link "C# Use Zip Archives without External Libraries" 使用标题作为 google 搜索项将文章置于首位。基本上它是关于 MS.Internal.IO.Zip 的包装器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2011-10-13
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多