在C ++中创建一个空的.zip文件 [英] Creating an empty .zip file in C++

查看:165
本文介绍了在C ++中创建一个空的.zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的代码段来自页面上如何创建一个zip文件,并添加和压缩一个目录到该zip文件。我在Windows 7上运行以下程序,但它似乎根本不创建zip文件。

  BSTR bstrFolderOutName = C:\\Test\\Archive.zip; 
BYTE startBuffer [] = {80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0};
FILE * f = _wfopen(bstrFolderOutName,Lwb);
fwrite(startBuffer,sizeof(startBuffer),1,f);
fclose(f);


解决方案

没有文件被创建,是不可能用给出的信息回答。这很可能是由于无效的文件路径。然而,OP在注释中声明他的示例中的路径不是真正的代码






编辑十六进制字符串示例,我刚才引用的是错误的,我刚测试。



此代码的工作原理:

  #include< stdio.h> 

auto main() - > int
{
FILE * f = fopen(foo.zip,wb);
// fwrite(\x80\x75\x05\x06\0\0\0\0\0\0\0\0\0\ 0 \0\0\0\0\0\0\0\0,22,1,f);
fwrite(\x50\x4B\x05\x06\0\0\0\0\0\0\0\0\0\0\\ \\ 0 \0\0\0\0\0\0\0,22,1,f);
fclose(f);
}

Harumph,人们甚至不能信任Stack Overflow的评论。




假设OP现在已编辑代码,以便下面的部分是真实代码,则此常数

  {80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0} 

不同

 \x80\x75\x05\x06\0\0\0\0\0\0\0\0\\ \\ 0\0\0\0\0\0\0\0\0\0

OP可以找到相关的差异吗?



他的信息来源?



我的例子来自其他地方的评论


I am using a code snippet from this page on how to create a zip file and add and a compress a directory to that zip file. I am running the following on Windows 7 but it does not seem to create the zip file at all.

BSTR bstrFolderOutName = L"C:\\Test\\Archive.zip";
BYTE startBuffer[] = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
FILE *f = _wfopen(bstrFolderOutName, L"wb");
fwrite(startBuffer,sizeof(startBuffer),1,f);
fclose(f); 

解决方案

The stated problem, that no file is created, is impossible to answer with the information given. It is most likely due to an invalid file path. However, the OP states in a comment that the path in his example is not the real code.


EDIT: the hex string example that I cited originally was wrong, I just tested.

This code works:

#include <stdio.h>

auto main() -> int
{
    FILE* f = fopen("foo.zip", "wb");
    //fwrite( "\x80\x75\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 22, 1, f );
    fwrite( "\x50\x4B\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 22, 1, f );
    fclose(f);
}

Harumph, one cannot even trust Stack Overflow comments. Not to mention accepted answers.


Original text:

Assuming that the OP now has edited the code so that the part below is the real code, then this constant

{80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

is not identical to

"\x80\x75\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

Can the OP spot the relevant difference?

Further, given that, can the OP infer anything about his source of information?

My example from a comment elsewhere.

这篇关于在C ++中创建一个空的.zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆