Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

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 Lua Downloads

Lua
local chilkat = require("chilkat")

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

local zip = chilkat.Zip.new()

local success = zip:open_zip("test.zip")
if not success then
    print(zip.last_error_text)
    return
end

local entry = chilkat.ZipEntry.new()

success = zip:entry_of("hamlet.xml", entry)
if not success then
    print(zip.last_error_text)
    return
end

entry.file_name = "hamlet2.xml"

success = zip:entry_of("helloWorld.pl", entry)
if not success then
    print(zip.last_error_text)
    return
end

entry.file_name = "hw.pl"

-- Now unzip to the "test" subdirectory, under our current
-- working directory:
local numFilesUnzipped = zip:unzip("test")
if numFilesUnzipped < 0 then
    print(zip.last_error_text)
    return
end

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