Libarchive to extract to a specified folder?

。_饼干妹妹 提交于 2019-12-01 06:54:13

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 );

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!