This object lets you create, add to, and extract from standard Zip archive files. An object of this class is created by calling the top-level function SPZip.
Adds files to the Zip archive.
void add(list, rootDir);
|list||String||List of files to add. See below.|
|rootDir||String||The root directory. If this is specified, the file specifications in "list" are relative to this directory and the path stored in the archive will be relative to this directory.|
If the archive already exists, this method adds the specified files, replacing any existing files with the same name. If the archive doesn't exist, it is created. If you wish to create a completely new archive, replacing any existing one with the same name, you must use the Script.deleteFile function first.
Multiple files can be specified by separating them with commas or line terminators. To include commas in the name, or for clarity, names can be enclosed in single or double quotes. Arrays of file names returned by functions like getFileList can be passed to add since they are automatically separated by line terminators when converted to strings.
Files can be explicitly excluded or included from the files in the list. To use this feature, first specify all the files and wildcards you want to process, then specify files to include or exclude among the files to process already specified. To exclude certain files, place a < symbol before the filename or wildcard expression to exclude, and add it to the list. To include only certain files, place a > symbol before the filename or wildcard expression. The include or exclude feature may only be used if the list contains at least one filename or wildcard expression without the < or > symbols. The include feature applies primarily when using addRecursive, since it allows you to specify all directories, but filter out only a specific file type within those directories.
z = SPZip("c:/backups/project.zip"); // Specify the zip file // "d:/project/*" says add everything inside folder "project". // "<*.obj" says exclude all files matching *.obj. // "<*.pch" says exclude all files matching *.pch. z.add("d:/project/*,<*.obj,<*.pch");
Adds files recursively to the Zip archive.
This method is identical to add except that it adds files in all subdirectories encountered recursively. This only applies when wildcards are specified in the file list. See the comments on file list format under add.
z = SPZip("c:/backups/text.zip"); // Specify the zip file // "d:/documents/*" says add everything inside folder "documents". // ">*.txt,>*.rtf" says include only files matching *.txt and *.rtf. z.addRecursive("d:/documents/*,>*.txt,>*.rtf");
Extracts files from the zip archive.
void extract(destDir, names);
|names||String||The names of the files to be extracted. The same rules for syntax and wildcard usage apply here as for add, except that the exclude feature is not allowed. If this is not specified, all files are extracted.|
|destDir||String||The full path name of the destination directory for the files extracted. Note that any path name stored in the archive will be used starting at this location.|
Gets a list of the files contained in the Zip archive.
Returns an array of SPFile objects representing the files in the archive.
IMPORTANT: In this version, the SPFile objects returned can only be used for extracting name and status information regarding the files in the archive. No operations (e.g. read, write, delete) are allowed on these objects. This may be added in a future version.