How to make a loop work?

Hi all! Please, help me. I do not know how to do it.
I have many files with different structures.
The file processing algorithm depends on the file structure.
How to make a loop work? Thanks all!

Hi @epikuron

I don’t what you want to achieve but, what I do know is to get the loop to work. You need one Loop End node, with two “Collector Ports”. Click on the 3 dots on the bottom left of the Loop End node to add a collector port.

gr. Hans

1 Like

I want a loop to iterate over a list of files. The files will be processed each according to their own algorithm (left or right), depending on the structure.

So that each file is read, and then the structure is checked. The files will be processed each according to their own algorithm (left or right), depending on the structure.

So, does my suggestion to use only one Loop End node gets your worklfow running?

Thank you but no. I need to read files with different contents using a loop. Then check its structure. Perform processing depending on the structure.

With the Table Row to Variable Loop Start , you can read in files with different structere. You need to check the “Allow changing table specifications” and “Allow variable column types” to keep the loop running.

How can you check the file structure after reading the file and send it to the required processing path?

OK, what do you mean by file structure? What do you want to check? Number of rows? number of columns? Column names? Column type? Possible Column Values?

Yes. Check number of columns, сolumn names and column type and send it for processing along the required path. Then move on to the next file.

Ok. what is the result after a file is checked. Is the result one record with the results per file like, the number of columns matches Yes/No or these are the matching columns (and these are the non matching columns). Or do you want the complete input file to split, in matching columns and non matching columns?

For structure number one - processing path (branch) number one, for structure number two - path (branch) number two. Checking the structure to send the file to the correct path for processing.

So that the program understands what kind of file was read and processes it in the necessary way. But I don’t know how to continue the loop in this situation

Hi @epikuron ,

By configuring the Table Validate (reference) as follows, it can act like a SWITCH node:

For each branch, the upper port is only processed if the branch is “active” and the lower port is processed for “inactive”. You can then terminate with an End IF , and each End IF then attaches to the appropriate port on the Loop End as follows:

It’s a bit convoluted, but I think it would work.

Process multiple files according to structure.knwf (87.0 KB)

[edit: reuploaded workflow!]

( see here for further info on the NoOp nodes, if you don’t know what these are)

1 Like

Hi, Takbb! I’ll try your solution

1 Like

Hi @epikuron , I hope I understood what you were trying to do!

But this gave me an idea for a new component, to remove some of the clutter! :slight_smile:

Process multiple files according to structure - with component.knwf (97.0 KB)


Hi @epikuron , I believe that the above solution would work for this. Please let us know if it doesn’t so alternative suggestions or tweaks can be made.

@epikuron I extended the solution by @takbb and included a CASE Switch node to initiate actions based on which format does match. One could also include that in the first switch though …

Process multiple files according to structure - with component - KNIME Forum (78663).knwf (190.3 KB)

1 Like