3

我需要以编程方式将 zip 存档解压缩到 Windows Mobile 上的文件夹中。是否有一个易于使用的 API 可以直接使用,还是应该使用一些外部库?

4

3 回答 3

7

您需要一个外部库。有一个 zlibce.dll,一个本地 DLL,如果 C++ 是您的首选,您可以使用它。

如果您喜欢 .NET,那么我可以推荐DotNetZip,它在 .NETCF 2.0 上运行,是免费的、开源的,并且具有良好的文档和良好的性能。在 DotNetZip 源代码分发中,有一个 CF-Unzipper 项目,您可以查看和编译;它演示了如何在设备上解压缩文件。这是一个链接,您可以在其中查看设备应用程序的代码

这是代码中与 zip 相关的部分的片段。它将解压缩到一个目录,该目录取自 zip 文件的名称(不带 .zip 扩展名)。

    private void UnzipSelectedFile()
    {
        string parent = System.IO.Path.GetDirectoryName(_selectedpath);
        string dir = System.IO.Path.Combine(parent,
            System.IO.Path.GetFileNameWithoutExtension(_selectedpath));
        try
        {
            using (var zip1 = new Ionic.Zip.ZipFile(_selectedpath))
            {
                foreach (var entry in zip1)
                {
                    entry.Extract(dir, true);
                }
            }

            // re-populate the treeview with the extracted files:
            AddChildren(tvFolders.SelectedNode.Parent);

        }
        catch (Exception ex)
        {
            MessageBox.Show("Exception! " + ex);
        }
    }

这是该库文档的在线版本的链接。

于 2009-03-06T09:42:46.640 回答
0

如果您使用的是 .Net Compact Framework,则可以使用http://www.icsharpcode.net/OpenSource/SharpZipLib。我相信它支持在 CF 上运行。

于 2009-03-06T09:23:03.207 回答
-1

无论您使用哪种语言,都可以将Info-ZIP用作外部可执行文件。

于 2009-03-06T09:47:54.893 回答