Sample code for 30+ languages & platforms
C

Change a Filename before Unzipping

See more Zip Examples

How to open a zip and modify the filename of one or more files within the zip before unzipping.

Chilkat C Downloads

C
#include <C_CkZip.h>
#include <C_CkZipEntry.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkZip zip;
    HCkZipEntry entry;
    int numFilesUnzipped;

    success = FALSE;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    zip = CkZip_Create();

    success = CkZip_OpenZip(zip,"test.zip");
    if (success == FALSE) {
        printf("%s\n",CkZip_lastErrorText(zip));
        CkZip_Dispose(zip);
        return;
    }

    entry = CkZipEntry_Create();

    success = CkZip_EntryOf(zip,"hamlet.xml",entry);
    if (success == FALSE) {
        printf("%s\n",CkZip_lastErrorText(zip));
        CkZip_Dispose(zip);
        CkZipEntry_Dispose(entry);
        return;
    }

    CkZipEntry_putFileName(entry,"hamlet2.xml");

    success = CkZip_EntryOf(zip,"helloWorld.pl",entry);
    if (success == FALSE) {
        printf("%s\n",CkZip_lastErrorText(zip));
        CkZip_Dispose(zip);
        CkZipEntry_Dispose(entry);
        return;
    }

    CkZipEntry_putFileName(entry,"hw.pl");

    // Now unzip to the "test" subdirectory, under our current
    // working directory:
    numFilesUnzipped = CkZip_Unzip(zip,"test");
    if (numFilesUnzipped < 0) {
        printf("%s\n",CkZip_lastErrorText(zip));
        CkZip_Dispose(zip);
        CkZipEntry_Dispose(entry);
        return;
    }

    // The filenames within the .zip are unchanged, but it unzipped
    // test/hw.pl and test/hamlet2.xm


    CkZip_Dispose(zip);
    CkZipEntry_Dispose(entry);

    }