简体   繁体   English

解压缩C ++中的目录

[英]Unzipping a directory in C++

I am creating a C++ program that will read a .docx's plain text. 我正在创建一个C ++程序,它将读取.docx的纯文本。 My plan of attack is to rename the .docx as a .zip and then unzip. 我的攻击计划是将.docx重命名为.zip,然后解压缩。 I then will rename the .xml file containing the text of the document as a .txt and parse it out. 然后,我将包含文档文本的.xml文件重命名为.txt并将其解析出来。

Right now I have figured out the renaming which was easy enough. 现在,我已经知道重命名很容易了。 I am now struggling with unzipping. 我现在正在努力解压缩。 I am very proficient in C++, but this is my first time I have been extending myself to real word applications and using it beyond the STL library. 我非常精通C ++,但这是我第一次将自己扩展到真正的单词应用程序,并在STL库之外使用它。

At first I tried many wrappers for C++ from the zlib library, but have not been able to get any of them to compile or work properly (it may be due to environment being in Cygwin). 最初,我尝试了zlib库中的许多C ++包装器,但没有使它们能够编译或正常工作(这可能是由于Cygwin中的环境所致)。 For that reason it seems I have to default to using the messy zlib code to do this. 因此,似乎我必须默认使用凌乱的zlib代码来执行此操作。 But from all the documentation and examples I can find it only shows zlib being used to read a .zip that is a compression of one file not multiple files. 但是从所有文档和示例中,我只能发现zlib用于读取.zip,它是一个文件的压缩,而不是多个文件的压缩。 I now don't know where to go from here and, like I said earlier, being completely new to the domain outside of STL I am feeling quite lost. 我现在不知道从这里去哪里,就像我之前说的那样,对STL之外的域完全陌生,我感到非常迷茫。

Any help or guidance is much appreciated! 任何帮助或指导深表感谢!

Thanks, Michael 谢谢迈克尔

zlib is for GZip compression, not ZIP compression ( see here for details ). zlib用于GZip压缩,而不用于ZIP压缩( 有关详细信息,请参见此处 )。

As a result you'd perhaps be better to shell out to the unzip utility provided in Cygwin and available for lots of platforms . 因此,最好使用Cygwin中提供的unzip实用程序,该实用程序可用于许多平台

I don't think zlib supports multi-file zips directly (could be wrong), so you may want to look for alternatives. 我认为zlib不直接支持多文件zip(可能是错误的),因此您可能需要寻找替代方法。 As an aside, you might also want to consider switching from cygwin to MinGW , unless you really need the POSIX/UNIX compatibility that cygwin provides. 顺便说一句,您可能还需要考虑从cygwin切换到MinGW ,除非您确实需要cygwin提供的POSIX / UNIX兼容性。

I've been dealing with a similar issue, but don't really have a great solution yet. 我一直在处理类似的问题,但实际上还没有很好的解决方案。

zlib does not currently support multiple files. zlib当前不支持多个文件。

See: C/C++ Packing and Compression 请参阅: C / C ++打包和压缩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM