Lua Requires Chilkat v11.0.0+
Lua
Unzip Selected Files from a Zip Archive
See more Zip Examples
Demonstrates how to iterate over the files contained within a .zip and unzip specific files.Chilkat Lua Downloads
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("my_files.zip")
if not success then
print(zip.last_error_text)
return
end
local unzipDir = "/temp/unzipDir"
-- Get the number of files and directories in the .zip
local n = zip.num_entries
local entry = chilkat.ZipEntry.new()
local i = 0
while i < n do
zip:entry_at(i, entry)
if not entry.is_directory then
-- (the filename may include a path)
print(entry.file_name)
-- Your application may choose to unzip this entry
-- based on the filename.
-- If the entry should be unzipped, then call Extract(unzipDir)
success = entry:extract(unzipDir)
if not success then
print(entry.last_error_text)
return
end
end
i = i + 1
end