One Star

[resolved] Pick single file from folder

Hi,
I want to pick a single file from a folder which may have multiple files of same format. This file can be any file.
How to do so? tFileList iterates on files and loads all the files one after other. I don't want this. I only want to load a single file instead.
1 ACCEPTED SOLUTION

Accepted Solutions
Seventeen Stars

Re: [resolved] Pick single file from folder

just find a tricky way to do that Smiley Happy
use the Talend variable NB_FILEtFileList_1 in a if condition after iteration on tFileList
if condition 
NB_FILEtFileList_1==1



3 iterations (3 csv file) but read only one (the first one)
ps : just a System.out in my tJava

System.out.println(NB_FILEtFileList_1);

 could be better to use a tWarn to log which file is iterate (current iteration)
hope it help
regards
laurent
10 REPLIES
Seventeen Stars

Re: [resolved] Pick single file from folder

I guess you need for some reason the tFileList component, otherwise your question is hard to understand because processing a single file is the default use case of the file processing components (like tFileInput* etc.).
You can set the file name in the tFileList as filter condition. Thats causes the tFileList to return exact this file.
One Star

Re: [resolved] Pick single file from folder

In tfileinput* we need to specify the file name. We can't use *.csv to pick a file.
I want to pick one file from the directory which may contain multiple files.
One File ---> TMap -----> tmysqlOutput
The don't know the file name but i know it is a csv file. (The folder can have multiple csv file at this time but i want to pick any one of them)
Seventeen Stars

Re: [resolved] Pick single file from folder

hi,
you don't know the name but how to identify it (for the filter or regex) ?
regards
laurent
One Star

Re: [resolved] Pick single file from folder

I just need to pick any file in that folder. 
The regex i would use is "*.csv" or "abc*.csv"
One Star

Re: [resolved] Pick single file from folder

If you want to control your no. of iterations then use tWaitForFile instead of tFileList.
One Star

Re: [resolved] Pick single file from folder

Thanks! 
But won't it process all the files if multiple files are uploaded in the directory?
One Star

Re: [resolved] Pick single file from folder

Processing of files depends upon parameters you will define in component setting
please look below screenshot and put same parameters (as in your case only)

Seventeen Stars

Re: [resolved] Pick single file from folder

just find a tricky way to do that Smiley Happy
use the Talend variable NB_FILEtFileList_1 in a if condition after iteration on tFileList
if condition 
NB_FILEtFileList_1==1



3 iterations (3 csv file) but read only one (the first one)
ps : just a System.out in my tJava

System.out.println(NB_FILEtFileList_1);

 could be better to use a tWarn to log which file is iterate (current iteration)
hope it help
regards
laurent
One Star

Re: [resolved] Pick single file from folder

Thank you m.gajvani 
Works fine now.
Seventeen Stars

Re: [resolved] Pick single file from folder

just a point about 'tWaitForFile' as solution.
as background process (waiting for something), you have to listen to if it's still alive & stil wait for new file Smiley Wink 
regards
laurent