overwrite Path variable, how to

Hello knimers
I am currently working with KNIME version 4.5.2 (yes, i know…)

I want to reuse one Path Variable many times -actually not in loop but it could be- so I don’t need to configure a writer every time with a different variable names.

I can edit with a ‘Java Edit Variable (simple)’ node, and with this node you can optionally overwrite a variable. But it only works with integer, double and string types. ‘Variable Expressions’ node only works on these three types as well.

return $${SmyPath}$$ + "\\" + $${Sfile_name}$$;
\\ overwrite >> $${Sfile_name}$$

Next I have to convert my string to Path, but overwrite it isn’t an option function. Then I end up with:

$${Pfile_name_location (#1)}$$
$${Pfile_name_location (#2)}$$ ...

Do you know how to overwrite Path Variables?

Thanks in advance

@gonhaddock currently there only seems to be the way to try and use a Component that would not let one variable thru.

Apparently there is a task (AP-16515) to create a variable filter. I think one will have to be careful since this might result in unintended consequences.

1 Like

The only way I can think of is using Merge variables to pull in the replacement path from a “new” branch. It is important that the branch containing the new variable is never connected to the existing flow as it will then generate a #1 version
Overwrite Path Variable.knwf (19.8 KB)

[edit: Of course if your new file name needs to use information from your existing flow, then this isn’t going to work because the moment the “Set File2 Name” node in the sample flow is connected to the existing flow, (ie if it receives flow variables from the main flow) the whole idea breaks. So not necessarily very useful! ]


Hi @takbb
I’ve checked the workflow and I can see that you already put some mind into this topic. It’s great to learn, but initially I can’t use this idea as I am not typing the variables (are generated from df names) and currently it is all connected.

I’m gonna give it a try connecting all in a different way, and I’ll let you know.


@gonhaddock I wonder if it might be possible to write information you want to have into a table and then read it back and convert the result to a Flow Variable. So once the information in the file has been changed the result from the Flow Variable would also change. I have not thought that thru and it is not pretty - but maybe you can provide us with a sample workflow that would demonstrate where you would like to change the Flow Variable.


I wonder if a new component would help here… I’m on 4.6.2 so I don’t know if these would work for you with 4.5.2,

Replace Path Variable - Component.knwf (41.0 KB)


Hi @mlauber71
Thanks for the second time in the day. I definitely will add +1 to the variable filter development. I could currently configure individually the writers (this was my initial thought) because they are tens, no hundreds. The variables are generated from R snippet DF names. But laziness push me to study all the options.

I will test the component as well.


1 Like

Good luck @gonhaddock. I uploaded the demo workflow to the hub adding some extra comments.

If you do get a chance to try the component, be sure to let me know if you discover any issues. I’ll probably start using it myself now as I’ve lost count of the number of times I’ve done String Manipulation (Variable) followed by String to Path (Variable) , thinking wouldn’t it be good if… :wink:

have a good weekend!


Hi @gonhaddock

To add to the already mentioned valuable information, have you considered the replacePath() option?

I used it in a column expression (variable expression has the same functionality I believe) for a case whereby I had a directory with folders based on numbers only. With some associated information, I reconstructed the Path with the replacePath() to create new folders.

For example:
replacePath(column("Path"),join(replace(column("path_to_str"),column("combined string") ,""),column("PARTNO"),"_",column("SERIALNUMBER"),"\\",column("FILENAME")))

which is similar to what you wrote:

$${SmyPath}$$ + "\\" + $${Sfile_name}$$;
\\ overwrite >> $${Sfile_name}$$

In your case, it would be something along the lines of:

replacePath(column("Path"),join(column("my_path"),"\\", replace(column("file_name"),column("file_name_new")))
whereby the last section acts as the overwrite.

If you need this a lot I would consider upgrading to V4.6 since Path is now a variable type within the expression node.


This is a good piece of information. replacePath + type Path type Variable Expressions would be indeed good reasons for the upgrade. For the time being Column Expressions in 4.5.2 manages a good bunch of format types as well. Then the problem would resides in ‘String to Path (Variable)’ node.

However I will upgrade the version once I finish this workflow, just in case.

Upgrading this Java Edit Variable (simple) to Return Path type would solve the whole workaround. Could you check in version 6 if this is already implemented? Otherwise this is a good feature to recommend for Feedback and Ideas.


This is still the same in V.4.6.3

First of all thanks to all of you for the constructive brainstorm. I finally came up with a solution using KNIME base nodes. This would be more similar to my use case; then it can be implemented in a continuous workflow or in a loop. I’m sharing my concept as requested by @mlauber71

I’ve tested @takbb component and I think that it’s good for most use cases. Good insights from it as well. That’s why I’m marking it as a recommended solution. At the end the variable has to be typed somewhere (in my case I coded in the R Snippet nodes) and these pop up dialogue boxes are very friendly.

All these workarounds could be avoided with the implementation of an ‘Overwrite Variable’ function within the ‘String to Path (Variable)’ node.



Thanks @gonhaddock. As you say these brainstorms are always useful…

And today I learned that path variables can be defined in the variable expressions node which is something I hadn’t previously spotted so thank you @ArjenEX for that useful info.


The forced persistence of flow variables in the main workflow has never made any sense to me. Why can’t we just treat flow variables the same as columns. We should be able to easily rename / filter out / overwrite flow variables in the exact same way as columns. It would open up a lot more options for users and cut down on clutter.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.