Extensions.ZipHandling.ZipFile

From emotive
Jump to navigation Jump to search

Classification

Name ZipFile
Short Description Compresses the file or folder
Class Action
Extension OTX ZipHandling extension
Group ZipHandling related Actions
Exceptions FileAlreadyExistsException
FileNotFoundException
Checker Rules ZipFiles_Chk002
Standard Compliant Yes

OTL Syntax

ZipHandling.ZipFile(StringTerm source, StringTerm target, ListTerm extensions, BooleanTerm append, BooleanTerm override);

Description

Compresses the file or folder denoted by the given source path. If the path points to a single file, only that file will be stored in the target file. If the path points to a folder, the folder and all its contents (files and subfolders in arbitrary depth) will be stored in the target file. In the case of a folder, that folder will be the root element in the target file.
It is possible to control which files to add by passing in a list of allowed file extensions. Only the files that match one of the given file extension strings will be added (including the folder structures they are contained in).
Furthermore it is possible to specify whether an existing target file will be overridden or not. Depending on whether the source(s) will be appended to an existing ZIP file, a flag controls whether or not the corresponding flag is set to TRUE, then any existing ZIP file will be silently overridden. Otherwise, if the flag is set to FALSE and the denoted target file already exists, an exception is thrown.

Properties

Name Data Type Class Default Cardinality Description
Source String - - [1..1] Contains the path to the to-be-zipped file or folder. The path will be a URI, relative to the OTX_HOME directory. If the file or folder denoted by this path does not exist or is not accessible, an exception is thrown.
Target String - - [1..1] Contains the path to the target ZIP file. The path will be a URI, relative to the OTX_HOME directory. If the file denoted by this path already exists and the override flag is not set or set to FALSE, then an exception is thrown. Also if the file already exists and cannot be overridden, or if it cannot be created at the given location, an exception is thrown.
Extensions List - - [0..1] The extensions element is a List of Strings. It contains a list of file extension strings. Only files, that have the given file extension (e.g. "txt": files ending with .txt) will be stored in the zip file.

This element is optional and if omitted, no filtering is performed, accepting any file with any file extension. In case, that files without an extension will be zipped an empty string is used.
It is possible to provide strings that contain wildcard characters. These are used as placeholders for arbitrary characters. The characters are:
⎯ '*' (asterisk) for an arbitrary amount [0..*] of consecutive characters.
⎯ '?' (question mark) for exactly one arbitrary character.
EXAMPLE:
With the extensions of ["t?t"] the following files will match (amongst others):
⎯ File.txt
⎯ File.tut
⎯ File.t1t
The following files will not match:
⎯ File.tt
⎯ File.text
⎯ File.log
EXAMPLE:
With the extension of ["log*"] the following files will match (amongst others):
⎯ File.log
⎯ File.log1
⎯ File.log_02
⎯ File.log.01
The following file will not match:
⎯ File.3log
⎯ File.lg.log
⎯ File.zip
IMPORTANT — Case sensitivity is platform dependent and may vary depending on the underlying system. It might therefore be necessary to provide a list with upper case and lower case variants of the same extension (e.g. "txt" and "TXT").

Append Boolean - - [0..1] If this flag is set to TRUE, then the to be zipped sources will be appended to an existing ZIP file, instead of replacing that ZIP file with a new one.

If this flag is omitted, it defaults to FALSE.
If the target ZIP file does not exist and the append flag is provided and resolves to TRUE, a FileNotFoundException is thrown.

Override Boolean - - [0..1] Determines whether an already existing target file will be overridden or not.

If the flag evaluates to TRUE, an existing target file will be silently overridden.
If it evaluates to FALSE, an existing target file will cause an exception to be thrown.
If the flag is omitted, it defaults to FALSE.
If the append flag is present and evaluates to TRUE, then the override flag concerns overriding files in the target ZIP file. This means, that the above mentioned rules are applied to the contents of the target ZIP file, possibly throwing a FileAlreadyExistsException, if any of the source files is already stored in the denoted ZIP file. In case an exception occurs the existing zip file will be unchanged.

OTL Examples

/// Global Declarations

public procedure main()
{
	/// Local Declarations

	/// Flow

	ZipHandling.ZipFile("file:///D:/FolderUnZipped", "file:///D:/FileZipped.zip", {"t?t"}, false, true);
}

See also

UnZipFile