0 ×

# Compress Files/Folder

KNIME Filehandling Nodes version 4.4.0.v202103310952 by KNIME AG, Zurich, Switzerland

This node supports the path flow variable. For further information about file handling in general see the File Handling Guide.

This node compresses files or a folder to an archive. If the compression format is being changed the file extension of the archive to create is adapted automatically.

Supported archive formats are:

• .zip
• .jar
• .tar
• .tar.gz
• .tar.bz2
• .cpio

## Options

Select a file system from which you want to choose files/folders which should be added to an archive. There are four default file system options to choose from:
• Local File System: Allows you to pack an archive with files/folder from your local system.
• Mountpoint: Allows you to pack an archive with files/folder from a mountpoint. When selected, a new drop-down menu appears to choose the mountpoint. Unconnected mountpoints are grayed out but can still be selected (note that browsing is disabled in this case). Go to the KNIME Explorer and connect to the mountpoint to enable browsing. A mountpoint is displayed in red, if it was previously selected but is no longer available. You won't be able to save the dialog as long as you don't select a valid i.e. known mountpoint.
• Relative to: Allows you to choose whether to resolve the path of files/folder that should be packed to an archive relative to the current mountpoint, current workflow or the current workflow's data area. When selected a new drop-down menu appears to choose which of the three options to use.
• Custom/KNIME URL: Allows to specify a URL (e.g. file://, http:// or knime:// protocol). When selected, a spinner appears that allows you to specify the desired connection and write timeout in milliseconds. In case it takes longer to connect to the host / write the file, the node fails to execute. Browsing is disabled for this option.
To read from other file systems, click on ... in the bottom left corner of the node icon followed by Add ports and Source file system connection. Afterwards, connect the desired file system connector node to the newly added input port. The file system connection will then be shown in the drop-down menu. It is grayed out if the file system is not connected in which case you have to (re)execute the connector node first. Note: The default file systems listed above can't be selected if a file system is provided via the input port.
Mode
Select whether you want to add single file, a folder or multiple files in a folder to an archive. When reading files in a folder, you can set filters to specify which files and subfolders to include (see below).
Filter options
Only displayed if the mode Files in folder is selected. Allows to specify which files should be included according to their file extension and/or name. It is also possible to include hidden files. The folder filter options enable you to specify which folders should be included based on their name and hidden status. Note that the folders themselves will not be included, only the files they contain.
Include subfolders
If this option is checked, the node will include all files from subfolders that satisfy the specified filter options. If left unchecked, only the files in the selected folder will be included and all files from subfolders are ignored.
File, Folder or URL
Enter a URL when reading from Custom/KNIME URL, otherwise enter a path to a file or folder. The required syntax of a path depends on the chosen file system, such as "C:\path\to\file" (Local File System on Windows) or "/path/to/file" (Local File System on Linux/MacOS and Mountpoint). For file systems connected via input port, the node description of the respective connector node describes the required path format. You can also choose a previously selected folder from the drop-down list, or select a location from the "Browse..." dialog. Note that browsing is disabled in some cases:
• Custom/KNIME URL: Browsing is always disabled.
• Mountpoint: Browsing is disabled if the selected mountpoint isn't connected. Go to the KNIME Explorer and connect to the mountpoint to enable browsing.
• File systems provided via input port: Browsing is disabled if the connector node hasn't been executed since the workflow has been opened. (Re)execute the connector node to enable browsing.
The location can be exposed as or automatically set via a path flow variable.
Write to
Select a file system on which you want to save your archive file. There are four default file system options to choose from:
• Local File System: Allows you to select a folder on your local system.
• Mountpoint: Allows you to write to a mountpoint. When selected, a new drop-down menu appears to choose the mountpoint. Unconnected mountpoints are greyed out but can still be selected (note that browsing is disabled in this case). Go to the KNIME Explorer and connect to the mountpoint to enable browsing. A mountpoint is displayed in red if it was previously selected but is no longer available. You won't be able to save the dialog as long as you don't select a valid i.e. known mountpoint.
• Relative to: Allows you to choose whether to resolve the path relative to the current mountpoint, current workflow or the current workflow's data area. When selected a new drop-down menu appears to choose which of the three options to use.
• Custom/KNIME URL: Allows to specify a URL (e.g. file://, http:// or knime:// protocol). When selected, a spinner appears that allows you to specify the desired connection and write timeout in milliseconds. In case it takes longer to connect to the host / write the file, the node fails to execute. Browsing is disabled for this option.
It is possible to use other file systems with this node. Therefore, you have to enable the file system connection input port of this node by clicking the ... in the bottom left corner of the node's icon and choose Add ports followed by Destination file system connection .
Afterwards, you can simply connect the desired connector node to this node. The file system connection will then be shown in the drop-down menu. It is grayed out if the file system is not connected in which case you have to (re)execute the connector node first. Note: The default file systems listed above can't be selected if a file system is provided via the input port.
File
Enter a valid path where the created archive should get saved. The required syntax of a path depends on the chosen file system, such as "C:\path\to\file" (Local File System on Windows) or "/path/to/file" (Local File System on Linux/MacOS and Mountpoint). For file systems connected via input port, the node description of the respective connector node describes the required path format. You can also choose a previously selected folder from the drop-down list, or select a location from the "Browse..." dialog. Note that browsing is disabled in some cases:
• Custom/KNIME URL: Browsing is always disabled.
• Mountpoint: Browsing is disabled if the selected mountpoint isn't connected. Go to the KNIME Explorer and connect to the mountpoint to enable browsing.
• File systems provided via input port: Browsing is disabled if the connector node hasn't been executed since the workflow has been opened. (Re)execute the connector node to enable browsing.
The location can be exposed as or automatically set via a path flow variable.
Create missing folders
Select if the folders of the selected output location should be created if they do not already exist. If this option is unchecked, the node will fail if a folder does not exist.
If exists
Specify the behavior of the node in case the output file already exists.
• Overwrite: Will replace any existing file.
• Ignore: Will ignore existing files
• Fail: Will issue an error during the node's execution (to prevent unintentional overwrite).
Compression
Allows to select the desired compression format.
Source folder truncation
Depending on the selected strategy the folder containing the files/folders to compress is being truncated differently, i.e., the folder structure in the resulting archive is being modified. For the remainder assume that folder/other/ is the selected folder and it contains the file folder/other/subfolder/file.txt
• Keep full path: This selection ensures that the folder's path is not being truncated, i.e., the archive will contain the entry folder/other/subfolder/file.txt (folder/other/file.txt if flatten folder is selected).
• Keep source folder only: This selection ensures that anything preceding the source folder's name is being truncated, i.e., the archive will contain the entry other/subfolder/file.txt (other/file.txt if flatten folder is selected).
• Truncate full path: This selection ensures that the folder's path is being fully truncated, i.e., the archive will contain the entry subfolder/file.txt (file.txt if flatten folder is selected).
• Truncate: This selection truncates the first occurrence in the folder's path matching the regular expression, i.e., the archive will contain the entry folder/subfolder/file.txt (folder/file.txt if flatten folder is selected) given the regular expression other.*.
If it is not possible to apply the selected truncation strategy the node will fail during execution.
Flatten folder
This option allows to specify where the files are located if multiple files have to be compressed. If checked all files are compressed to the same folder, otherwise the archive will contain also the folder containing the files. Note: If the (source) folder gets flattened it might occur that two files with the very same name end up in the same location. In this case the execution will fail.
Include empty folders
This option allows to specify whether or not empty folders should be included in the archive.

## Developers

You want to see the source code for this node? Click the following button and we’ll use our super-powers to find it for you.