Edit Path Variable Filename (branch safe)

This is a modified version of the original Edit Path Variable Filename which, because of a KNIME bug could not operate inside a conditional branch within KNIME. This version differs only in that the returned path variable name is always given the prefix "path_" and therefore cannot replace an existing path variable.


Allows on-the-fly "editing" of an input path and file name using string concatenation (additon of simple prefix or suffix to a filename) or replacement of filename using regex, and direct replacement of filename extension.

Also allows the folder path to be modified using regex replacement.

Where regex is used, it follows the regex required by the String Manipulation regexReplace function, so any use of a \ within a folder path must be entered as double-backslash \\ so that regex does not misinterpret the character.

Example replacement that could be performed:

For an incoming file path representing

c:\myoutputfolders\excel\somefile.xlsx

Setting:
prefix: accounts-
suffix: -formatted
regex file search: (.*)file
regex file replace $1sheet
regex folder search: (.*)\\myoutputfolders\\(.*)
regex folder replace: $1\\formattedoutputs\\$2

would result in the output file:
c:\formattedoutputs\excel\accounts-somesheet-formatted.xlsx


@takbb Brian Bates 28 October 2023

Options

Create additional STRING Variable containing new path (absolute path)
Select this option to also create a String Variable containing the new path, in addition to the path variable. It will be given the same name as the Path variable but with the addition of -str suffix
Choose source path variable
Choose the path variable that contains the file name that you wish to edit
Replacement Extension (e.g. csv, xlsx, json) Do not include the "."
Enter the new extension for the file (or leave blank to keep existing)
New Filename prefix
Enter a prefix to add to the start of the file name (or leave blank)
New Filename Suffix
Enter a suffix to add to the end of the file name (or leave blank)%%00010
Enter regex pattern to replace
Enter a regex pattern to replace in the file name (does not include folder path or extension).%%00010%%00010default of ^(.*?)$ is used to replace entire string.
Enter replacement string (can include regex capture groups)
Enter the string value to use in replacing the specified file name string. You can use $1, $2 etc as regex capture groups
Path variable name to create (leave blank use source variable name)
Enter a name for the new path variable. The returned variable will have the prefix "path_" followed by the specified name. %%00010%%00010This version of the component is the "branch safe" version which can be used within conditional branches in a KNIME workflow. The addition of a fixed prefix on the returned variable is a necessary workaround to a KNIME bug (at time of writing in KNIME 4.7.7 and 5.1.1) to allow the component to operate within a condition branch.
Folder regex pattern to replace. Use \\ in place of \
Enter a regex pattern to replace in the folder. For backslashes in folder names use double-backslash \\%%00010%%00010default of ^(.*?)$ is used to replace entire folder.%%00010%%00010N
Folder replacement string (can include regex capture groups). Use \\ instead of \
Enter the string value to use in replacing the specified folder name string. You can use $1, $2 etc as regex capture group

Input Ports

Icon
No description for this port available.

Output Ports

Icon
No description for this port available.

Nodes

Extensions

Links