libarchive解压到指定文件夹?

发布于 2024-10-08 17:43:49 字数 406 浏览 0 评论 0原文

任何人都可以帮助展示使用 libarchive 将 ZIP 文件提取到的示例指定的文件夹?看起来提供的示例程序(untar.ctarfilter.cminitar)都将存档提取到当前工作目录。有没有办法对 libarchive 说“提取到此文件夹及以下文件夹”而不破坏程序的活动文件夹?

主要驱动因素之一是提取代码将在后台线程中运行,因此更改程序工作目录可能会产生问题。此外,这还将在 iOS 应用程序(iPhone、iPad)中使用,该应用程序对应用程序可以写入的文件夹很挑剔。

提前致谢。

Anybody can help show examples of using libarchive to extract ZIP files to a specified folder? It looks like the sample programs provided (untar.c, tarfilter.c and minitar) all extracts the archive to the current working directory. Is there a way to say "extract to this folder and below" to libarchive and not clobber the program's active folder?

One of the main drivers is that the extraction code will be run in a background thread, and thus changing the program working directory may create problems. Also this will be used in an iOS application (iPhone, iPad), which is picky on what folders that the application can write to.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ら栖息 2024-10-15 17:43:49

您可以在调用 archive_read_extract 之前重写每个 archive_entry 的路径名。例如:

const char* path = archive_entry_pathname( entry );
char newPath[PATH_MAX + 1];
snprintf( newPath, PATH_MAX, "/SomeOtherDirectory/%s", path );
archive_entry_set_pathname( entry, newPath );

You can rewrite each archive_entry's pathname before calling archive_read_extract. For example:

const char* path = archive_entry_pathname( entry );
char newPath[PATH_MAX + 1];
snprintf( newPath, PATH_MAX, "/SomeOtherDirectory/%s", path );
archive_entry_set_pathname( entry, newPath );
允世 2024-10-15 17:43:49

通过将要使用的路径添加到传递给 create_dir()create_file()< 的路径名前面,可以轻松修改 untar.c 来实现此目的/code> 来自 untar()

请注意,untar.c 是一个独立的解压缩器,与 libarchive 分开。

使用 libarchive 可以轻松实现相同的效果 - 它使您可以在解档时完全控制文件和目录的创建。

untar.c can be easily modified to do this by prepending the path you want to use to the pathname that is passed to create_dir() and create_file() from untar().

Note that untar.c is a standalone decompressor, seperate from libarchive.

The same effect is easily achievable with libarchive - it gives you full control over the creation of files and directories when unarchiving.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文