One Star

tWaiForFile - Is it possible to specify more than 1 file to wait?

Hello,
I have about 10 files which I need to wait in order to begin processing. How can I do this with tWaitForFile? Where can I put the names of the files that I need to wait? Please help.
Thanks in advance.
8 REPLIES
Community Manager

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

Hello
Select a directory and set the file mask, please read the user documenation, there is a demo job.
Let's us if you have any trouble.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

Thank you for your reply Shong. Can you please show me how I can configure the tWaitForFile for these specific file names in a directory?
These are the only file names I need out of all other files with same extension .tap.asc in a directory:
samplea.tap.asc
sampleb.tap.asc
samplec.tap.asc
sampled.tap.asc
samplee.tap.asc
samplef.tap.asc
Thanks.
Employee

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

Can you try this in filemask property --> sample*.tap.asc
One Star

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

there will be sampleg.tap.asc, sampleh.tap.asc, etc.. which I do not need to wait. Is it possible to specify the exact names of files to wait in the filemask property? I tried with a comma after each file name and did not work.
Thanks.
Community Manager

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

Hello
Set the filemask as "*.tap.asc", get the filename on tJava and compare it with a list of files which you want to extract, if true, do next transaction. eg:
tJava_1
|
onsubjobok
|
tWaitForFile_1--iterate-->tJava_2-runIf->tFileInputDelimited_1--main-->tLogRow
On tJava_1: define a list of files which you want to extract eg:
java.util.List<String> list=new java.util.ArrayList<String>();
list.add("bug1126.abc.txt");
list.add("sampleb.tap.asc");
globalMap.put("mylist",list);

on tJava_2
boolean condition=false;
java.util.List<String> list1=(java.util.List<String>)globalMap.get("mylist");
String filename =((String)globalMap.get("tWaitForFile_1_FILENAME"));
for(int i=0;i<list1.size();i++){
if(filename.equals(list1.get(i))){
condition=true;
break;
}
}

globalMap.put("condition",condition);

runIf condition:
(Boolean)globalMap.get("condition")

set the file name of tFileInputDelimited_1:
(String)globalMap.get("tWaitForFile_1_CREATED_FILE")

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

I did exactly as you showed above but kept getting error at tFileInputDelimited_1 connecting to socket on port 3590
Exception in component tFileInputDelimited_1
java.lang.NullPointerException
I set the file name of tFileInputDelimited_1:
(String)globalMap.get("tWaitForFile_1_CREATED_FILE")
I don't know much about java and could not figure out what's wrong. Please advise.
Community Manager

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

Hello
First, make sure there is a component labeled tWaitForFile_1 in your job.
Second, print the global variable and see if it is null or not.
tJava_1
|
onsubjobok
|
tWaitForFile_1--iterate-->tJava_2-runIf->tJava_3
on tJava_3:
System.out.println((String)globalMap.get("tWaitForFile_1_CREATED_FILE"));

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tWaiForFile - Is it possible to specify more than 1 file to wait?

1 more question Shong, how can I make it wait and not to do anything until all the specified file names arrive?
For example, I need all these file names bug1126.abc.txt, sampleb.tap.asc and samplec.tap.asc to be present in a directory before they get copied to a different folder for processing. If one of the listed files is missing, then it needs to wait until all show up in order to move on to next processing step.
Thanks.