我现在需要解压instanll.zip压缩文件,但是有一个文件夹sysProp,
如果当前目录存在就不会覆盖该文件夹,其余正常解压!
新手求指教,望大神帮忙!!!万分感谢
最好友实现的代码,刚刚接触c++ Builder望见谅
c++ Builder解压,不覆盖已存在的文件
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- ChatGPTᴼᴾᴱᴺᴬᴵ 2023-05-26 23:57关注
该回答引用ChatGPT-3.5,仅供参考,不保证完全正确
以下是一个示例代码,用于解压install.zip文件,并在当前目录中检查是否存在sysProp文件夹。如果存在,则不覆盖该文件夹,否则进行正常解压。
#include <iostream> #include <zip.h> #include <cstring> bool directoryExists(const char* path) { DWORD attrib = GetFileAttributesA(path); return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); } void extractZip(const char* zipFilePath) { HZIP hz = OpenZip(zipFilePath, nullptr); ZIPENTRY ze; GetZipItem(hz, -1, &ze); int numEntries = ze.index; for (int i = 0; i < numEntries; ++i) { GetZipItem(hz, i, &ze); std::string entryName = ze.name; std::string entryPath = "./" + entryName; // Check if sysProp directory already exists if (entryName == "sysProp" && directoryExists(entryPath.c_str())) { std::cout << "sysProp directory already exists. Skipping extraction." << std::endl; continue; } if (ze.attr & FILE_ATTRIBUTE_DIRECTORY) { // Create directory CreateDirectoryA(entryPath.c_str(), nullptr); } else { // Extract file ExtractZipItem(hz, i, entryPath.c_str()); } } CloseZip(hz); } int main() { const char* zipFilePath = "install.zip"; extractZip(zipFilePath); return 0; }
这段代码使用了zlib库中的zip.h头文件中的函数来解压zip文件。在每次迭代时,它会检查是否存在sysProp文件夹,并跳过该文件夹的解压过程。其他文件和文件夹会按照正常流程进行解压。
请确保已经正确链接zlib库,并将该代码添加到您的C++ Builder项目中。
解决 无用评论 打赏 举报
悬赏问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?