I am very new to KNIME and I am having trouble implementing the following loop:
I’d like to read all the Excel tables in a folder and create a csv table for each of them that has the same name as the original, only with .csv insteal of .xlsx of course.
So far I have a List Files/Folders → table row to variable loop start → excel reader → a bunch of column filters → CSV writer, but I am not sure which loop end node ot add. I suspect I have to have the loop end connected “in parallel” to the writer so that it doesn’t concatenate all the tables, but I am still unsure how to do this.
Can anyone help me? Thanks!
Hello @rita_vp and welcome to the forum.
Have you tested to connect the ‘csv writer’ to the ‘loop end’ by using the variables port?
Or any other node to be run sequentially afterwards.
Hi @rita_vp -
I suspect you need the Variable Loop End node here. This type of loop end node is useful when you don’t need to collect all the iterated data in a table, because the “magic is happening” somewhere else (in this case, filtering and writing files).
A dummy workflow might look something like this:
Hi @rita_vp , and welcome to the Knime Community.
As long as you have the CSV Writer inside the loop, then it’s going to write to different CSV files, as long as to give it a different file name (basically same file name as original file, except for the extension).
For the loop end, you can use the Variable Loop End since you are going with Table Row To Variable Loop.
I put something together for you, and it looks like this:
And this is the folder before the workflow is run:
And after the workflow is run:
As you can see, the workflow created 5 separate csv files.
And here’s the workflow:
Read Excel files and Create CSV files with same name.knwf (55.3 KB)
Nice @bruno29a! I should’ve been thinking about the treatment of file paths - your solution is definitely more complete than mine, and more useful
I think this is what I needed. I am not sure what I was thinking, because I definitely tried the variable loop end, but I must have used it wrong. Thanks!
Thanks to you too! I definitely needed the Variable Loop End, but I think I probably wasn’t getting how that worked exactly. My humble opinion is that sometimes the definitions and explanations on the nodes are a bit difficult to grasp when you are so new to Knime. However I am really getting to appreciate the tool. Thanks for you help!
Yes this was exactly my problem. I don’t think I had completely understood how to close my loop. I still have a question regarding the loop end, though: is there a way that I can edit the ending condition? I understand that this loop (the one I am using is very similar to the answer I marked as solution, basically just connecting the loop end node as you said) will stop when all the input files are read and transformed into csv, am I wrong? This is what I want, but for didactic purposes I would like to know how to change it
Hi @rita_vp , it’s always a good idea to show or share your workflow when you have a problem, which would allow us to point out what the issue might have been.
There are various ways to end a loop, but in this case, since the last operation is the CSV Writer, it made sense to use the Variable Loop End, as the CSV Writer does not have any output, except for the flowvariable (all nodes have flowvariable input and output ports). Had the last operation have a dataflow as output, for example String Manipulation, it would have made sense to use the Loop End instead.
That would require Variable Condition Loop End node.
Additionally here are some learning materials about loops:
Welcome to KNIME Community!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.