Question

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); 
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top