I have a list of files with this filename format pattern: name$Month_$Year.csv
What i want to do is to “List Files” node to list only the Current_Month + Previous_Month files based on the current month.
Hi there @rsalencar,
List Files node can list files using regular expression. So one idea is to based on current month you construct proper regular expression that will give you only two files you want - current and previous month based on execution date.
For example this expression can be used:
This syntax does it in Column Expressions node:
d = new Date(); n = toInt(d.getMonth()); join(".*(", n, "2020|", n-1, "2020).csv")
(Need to watch when you are in January and want file from last year. If that is the case you need to modify above code a bit).
If you want to avoid scripting nodes to construct regular expression you should play a bit with Date&Time nodes (get current and previous month as variables) and then use similar logic in String Manipulation node.
KNIME_forum_23111.knwf (10.7 KB)
If you want you can also customize filename by flow variable!
Hi pigreco, thank you in advance, one last question, how do i read this 2 output variables to in my next “List Files” node?
Thank you ipazin, but i think i dont want to open this workflow to changing years.
I am trying a node instead. Thank you so much.
You don’t need List Files Node because you have two rows, one for every file.
So you have to append StringTo URI Node to pass field to file reader.
“\server\Private\Adm\Custos\Análises\2020\1. PP_Output\NA_ksb1” + string(“ksb1”+$Date&Time$)+".csv" any clue why its nor working?
Are you sure that is right that ksb1 is repeated two times?
Which error do you have?
yes, it is, the full path would be:
*filename contains “ksb1” in my case.
First error is, after the “String to URL” node, the row value keeps starting with c:/knime…etc…and them \myserver\Private… is appended.
Second, characters line “á” “\” are not displayed properly.
- sorry for the questions mate i am just starting with Knime.
Thanks for your help
The reason is that build path is relative and the root is your knime dir.
At this moment I’m not in front of my pc, but, if I’m not wrong, you have to build your path starting with “file:///C:/…”
Hi pigreco, thank you, this first problem related to the URL is solved, now the error is related to the “File Reader” node, it cant ready the following url because it looks like its not in the “ASCII” format…
This is the URL that the node is passing to File Reader:
As you can see, there are some spaces and " ´ ".
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.