Hi Talend Folks,
Firstly, whenever possible you should use ISO 8601 format dates (YYYY-MM-DD) especially for filenames, as they can be sorted alphabetically which will also be chronologically, making things a lot easier in most situations. With the current format of your filenames, it would be ridiculously messy finding the most recent one(s) based purely on the name.
However, in this case we can presumably use the file modified date to get the two most recent files, as follows:
The key is to have the files in the tFileList sorted by modified date, and descending; then it's just a case of recording the filenames for first two files.
You may want to use "abs_path" instead of "basename" which I've used in my example, and obviously you should remove the System.out.println lines, which are just there to demonstrate that it's working.
Thank you for your reply
when I ran your query. i am getting error message.
Error Line: 880
Detail Message: The method containskey(String) is undefined for the type Map<String,Object>
if (row6.basename !=null)
It's actually Java code, and Java is a case sensitive language. The method is "containsKey" (with a capital "K").
I really should have included the code in my post, rather than just a screen grab, so you could copy it.
When in a code editor, or any text field which accepts expressions, you can press Ctrl + Space to bring up auto-complete suggestions, which also provide some basic documentation for functions like this.
If you change "row1.basename" to "row1.abs_path" in my example to keep things simple, then you can load the Excel files using two tFileInputExcel components, with the "File name/Stream" set to:
((String)globalMap.get("filename_latest")) or ((String)globalMap.get("filename_previous"))
These components would be in another sub-job, which would be connected to the first (which gets the most recent two filenames) using an "On Subjob Ok" trigger.
In your original example, you'd not need the two tFileList components, and the tFileInputExcel components would use the above as filenames, but otherwise it should just be the same.
As you said i have tried that flow but i can't join tFileinputExcel_5 to tmap_4
As you said , can you please make screenshot for me
If you just remove the OnSubjobOk going to tFileInputExcel_5, then you'll be able to join it to tMap_4.