I need to split this table based on each key (Key column) and create a txt file for each key.
I read something on this forum and i know I have to use the node “Table Row To Variable Loop Start” but I can’t do the same thing
Any idea is highly appreciated. Thank you very much in advance!
as @Daniel_Weikert mentioned, you can either ‘groupby’ the data or filter the duplicates and use a loop approach.
i’m attaching my loop workflow for you to review KNIME_filenames.knwf (95.7 KB)
I appreciate your response. However, the duplicate lines are not visible in the output file. In the example you provided, not all the lines from “b2011” are included.
actually it is not possible to have the same filename in a directory.
in those workflow examples, the goal is to remove duplicate filenames , using a loop concept and writing the files to the selected directory.
however, if all the files or keys are unique, and we still want to create them, then we should give them unique file names.
in this example, the “rowid” is appended to the filenames to make them unique.
several node adjustments to be made.
I’m afraid I might not have expressed myself clearly earlier. My goal isn’t to have two files with the same key, but rather to have the lines associated with the same key in a SINGLE FILE.
The method you described works correctly for a single execution. However, the issue that arises is that during each workflow execution, the data is written to the same files, which is not desirable.
Another question, please: Is it possible to write to a folder that doesn’t exist yet and allow me to choose the writing path? Thank you in advance.
Hi @mosmel , to try to answer your additional questions, yes KNIME can create the path if it doesn’t exist. If you use the CSV Writer node (not the deprecated version) you will find it has an option to “create missing folders”. I’d recommend issuing this rather than the deprecated nodes.
What I would typically do is construct a String flow variable with the full path and filename that I require and then use String to Path (Variable) to make a Path variable that can be used with CSV Writer. You can alternatively use the Create File/Folder variables node.
If you don’t want the file names to be the same on each invocation of the workflow, then you need to decide whether you want to make part of the folder path or the filename change each time. You could include a string based on execution current date and time perhaps? Or did you have something else in mind?
You might find the following link useful as an example of incorporating execution date into output file names…