Get a local file path and relative path of the same folder

Hello KNIMErs

As part of a workflow that will be deployed to a KNIME server I need to:
a) create a temp folder within the workflow directory - done!
b) get the path relative to the local workflow data area - done!
c) get the local file path for that new folder e.g. C:\KNIME\WorkFlows\CoolFlow\data\Process\6cfc7cf6-011d-4819-aee9-663019823951 - NOT done

I know I can hardcode strings to append and create a local file path, but, this part of the flow, is / will be a component which will be used by my colleagues and should work where ever its used.

Does the KNIME collective have the answer to this?

I have uploaded the flow that I have been playing with:

Many thanks



There is probably a KNIME node to get the current working directory. If not, then you can paste the following into a Python Script node. You will need to remove the input table and leave the output table on the node (three dots on node gives a menu to remove ports).

import as knio
import pandas as pd
import os

cwd = os.getcwd()
knio.output_tables[0] = knio.Table.from_pandas(
    pd.DataFrame([{"cwd": cwd}])

If you run this node it will output a table with the root of the current workspace directory.

LinkedIn | Medium | GitHub

1 Like

Hi @FrankColumbo , if the file you are creating is always relative to the workflow data area, you can find the workflow data folder absolute path from the Extract Context Properties node. This returns a set of contextual flow variables. One of these is the
context.workflow.absolute-path which is a String containing the absolute path to your workflow. The data area will then be this plus “/data” and you can concatenate your random folder name on to that.

The attached shows two ways of returning this as a String (using Variable Expressions, or String Manipulation (Variable) nodes )


An alternative method borrows from this post:

This converts the KNIME path into an absolute file location.

I have a component that I wrote a back in December 2022, based I think, on @qqilihq’s above solution

The attached flow contains the above options
FORUM - get different file paths.knwf (45.9 KB)


Cool! thank you @takbb

1 Like

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