Create a ZIP archive (file.zip)
Declaration
ok, err = file.zip(zipPath, filesOrDir [, password])
Parameters
- zipPath
String. Output path of the ZIP file to create. - filesOrDir
Table | String.- Table: each element is
{ sourcePath, archivePath }
, wherearchivePath
is the relative path inside the ZIP. - String: a directory path to pack into the ZIP.
- Table: each element is
- password
String. Optional. If provided, creates an encrypted ZIP.
Returns
- ok
Boolean. true if success, false if failure. - err
String. Error message when operation fails.
Notes
Compress files or a directory into a ZIP archive.
WhenfilesOrDir
is a table, you can precisely control the relative paths written into the ZIP. When it is a string, the entire directory content is packed. Available in versions after 2025-09-14.
Examples
Use a table to set archive paths
local ok, err = file.zip(XXT_SCRIPTS_PATH.."/out.zip", {
{ XXT_SCRIPTS_PATH.."/data/readme.txt", "docs/readme.txt" },
{ XXT_SCRIPTS_PATH.."/assets/logo.png", "assets/images/logo.png" },
}, "123456")
if not ok then
sys.alert("Zip failed: "..err)
else
sys.alert("Zip succeeded: "..XXT_SCRIPTS_PATH.."/out.zip")
end
Zip a directory directly
local ok, err = file.zip(XXT_SCRIPTS_PATH.."/project.zip", XXT_SCRIPTS_PATH.."/project")
if not ok then
sys.alert("Zip failed: "..err)
else
sys.alert("Zip succeeded: "..XXT_SCRIPTS_PATH.."/project.zip")
end
Note: Uses sys.alert