Nested loop for list of files

Hello

I have a list of files-I want to process the first file with the rest files, then the second file with the rest files.

How can I do that?

 

Best

Malik

Hi Malik,

You could start with a List files node that creatves a table with paths to all files within the specified location. Next you use a Table Row To Variable Loop Start node, which takes one path from the table for each iteration. Within the loop you can do whatever you want with the current file (I didn't really get what you mean by saying "process the file with the rest files") and use a Loop End node afterwards. Hope that helps.

Cheers,
Marten

Hi Marten

I have implemented it using two loops. I need to improve it more. If the file list has 3 files, say f1,f2,f3, i want to work on 

f1-f2

f1-f3

f2-f3

My workflow performs all the options

f1-f2

f1-f3

f2-f1

f2-f2

f2-f3

f3-f1

f3-f2

f3-f3

Do you have suggestions how to implement that?

Best

Malik

 

The simplest way to do this is probably with a little bit of scripting. In an R Snippet node the following code ought to do what you want (if you have a list of filenames in the input column Filenames):

fileList <- array(knime.in$"Filenames")
fileCombos <- combn(fileList, 2)
knime.out <- data.frame(fileCombos[1,], fileCombos[2,])

The output will have two columns containing each possible unordered pair of the input filenames. Now you can loop over the rows of this table using a KNIME loop.