Automating Workflow Generation: Creating .knwf Files with File Readers Programmatically

Hello everyone!

I’m working on a tool that automatically generates a KNIME workflow (*.knwf) from a folder path by creating one File Reader (or CSV Reader) node per file in that folder. I’ve come up with two possible approaches:

1.

Manually Generating the Workflow Files

Essentially, I’d replicate how KNIME structures a workflow on disk.

  1. I’d create a folder containing `workflow.knime` for the main workflow settings, plus subfolders under `nodes/` (e.g., `node_0/`, `node_1/`, etc.) for each reader node’s `settings.xml` file.

  2. After populating the settings for each node (pointing to the correct file path, delimiter info, etc.), I’d zip it all up and rename the zip to *.knwf.

  3. This requires carefully mirroring KNIME’s internal file and folder layout but can be done without a running KNIME environment.

1.

Using KNIME’s Java API

I’d write code (e.g., in an Eclipse plugin or a headless KNIME application) that instantiates a new

WorkflowManager

, programmatically adds nodes (e.g. CSV Reader node containers), configures them (file path, delimiter, etc.), then uses the KNIME core classes (e.g.

WorkflowPersistor

,

WorkflowSaveHelper

) to write the workflow to disk.

  1. This approach is “cleaner” as it stays within KNIME’s official APIs. However, it might require some knowledge of internal classes and typically needs to run inside a KNIME/Eclipse/OSGi environment.

I’d appreciate any thoughts or experiences with either method. Which do you think is more robust in the long term? Are there any pitfalls with direct file creation vs. using the KNIME API?

Thanks in advance for your help!