One Star

Advanced filtering with tFileList

Hi everybody,
I am newbie with Talend and English is not my native language ...
Each minute (using tInfiniteLoop), i would like to list files from a directory but only retrieve files respecting functionnal requirements (a file can only be retrieve if it exists its equivalent in .old. For example the file A.xml will only be retrieve if B.xml.old also exists).
So i think that Filemask and Exclude Filemask of tFileList component are not enough to do the job.
I try to do the job using tJavaFlex but it does not work.
Example of code :
<Start Code>
File dir = new File("D:/Works/InfoServer-Phase2/Input");
FilenameFilter filenameFilter = new FilenameFilter() {
public boolean accept(File file, String name) {
return name.endsWith(".xml");
}
};
List<File> Files = new ArrayList<File>();
for (File f:dir.listFiles(filenameFilter))
Files.add(f);

int nbFile=0;

<Main Code>
for (File f:Files){
String currentFileName = f.getName();
String currentFilePath = f.getAbsolutePath();
String currentFileDirectory = f.getParent();
String currentFileExtension = null;
if (f.getName().contains(".")&& f.isFile()) {
currentFileExtension = f.getName().substring(f.getName().lastIndexOf(".") + 1);
} else {
currentFileExtension = "";
}
nbFile++;
globalMap.put("tJavaFlex_1_CURRENT_FILE",
currentFileName);
globalMap.put("tJavaFlex_1_CURRENT_FILEPATH",
currentFilePath);
globalMap.put("tJavaFlex_1_CURRENT_FILEDIRECTORY",
currentFileDirectory);
globalMap.put("tJavaFlex_1_CURRENT_FILEEXTENSION",
currentFileExtension);
globalMap.put("tJavaFlex_1_NB_FILE",
nbFile);
}
Rem : It was a test so FilenameFilter is quite easy ;-)
My design is so:
tInfiniteLoop -------iterate-------> tJavaFlex (with code above) --------iterate---------tXSLT (using ((String)globalMap.get("tJavaFlex_1_CURRENT_FILEPATH"))
So my idea was to simlulate, using tJavaFlex, the behavior of a tFileList component.
Thanks in advance for your analyse and your helps ;-)
6 REPLIES
Community Manager

Re: Advanced filtering with tFileList

Hi
(a file can only be retrieve if it exists its equivalent in .old. For example the file A.xml will only be retrieve if B.xml.old also exists).

Sorry, I don't understand your requirements well.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Advanced filtering with tFileList

hi all,
Do you want to compare the name of file, the content ??
If you want to simulate a tFileList with tjavaFlex have a look at the of it ?
(view->talend->codeviewer and choice start,main,end,all in the right menu)
regards
laurent
One Star

Re: Advanced filtering with tFileList

Hi
(a file can only be retrieve if it exists its equivalent in .old. For example the file A.xml will only be retrieve if B.xml.old also exists).

Sorry, I don't understand your requirements well.
Best regards
Shong

Sorry shong, it seems that my requirements are not clear enough.
From a directory, i would like to list all the xml file having an associated .old file.
For e.g if directory contains following files
A.xml
A.xml.old
B.xml
C.xml
C.xml.old
I only want to get A.xml and C.xml files because B.xml has not related .old (B.xml.old) file
How can i achieve this ? (Exlude) Filemask of tFileList component can not help me to fullfill the complete filtering i need. So i think about creating a special component with tJavaFlex and simulate what tFileList does but with a more possible complexe filtering (like explain above)
I hope its is more clear now ;-)

Thanks for your interest and your help ;-)
One Star

Re: Advanced filtering with tFileList

hi all,
Do you want to compare the name of file, the content ??
If you want to simulate a tFileList with tjavaFlex have a look at the of it ?
(view->talend->codeviewer and choice start,main,end,all in the right menu)
regards
laurent

In fact i want to compare the name of the files and the "relation" between them like i explain here above to shong
Thanks for this trick, it can help ;-)
Employee

Re: Advanced filtering with tFileList

Well you do a tFileList only on file without .old extension right after you do a tFileExist to test if yourFileName+".old" exists in the folder. If Yes you get the files if not you proceed to the next file...
Six Stars

Re: Advanced filtering with tFileList

Hi
(a file can only be retrieve if it exists its equivalent in .old. For example the file A.xml will only be retrieve if B.xml.old also exists).

Sorry, I don't understand your requirements well.
Best regards
Shong

Sorry shong, it seems that my requirements are not clear enough.
From a directory, i would like to list all the xml file having an associated .old file.
For e.g if directory contains following files
A.xml
A.xml.old
B.xml
C.xml
C.xml.old
I only want to get A.xml and C.xml files because B.xml has not related .old (B.xml.old) file
)
Just use tfilelist to select "*.old" files.
Then just strip with string operation the trailing .old from the variable returned by tfilelist...