Showing posts with label talend name of last modified file. Show all posts
Showing posts with label talend name of last modified file. Show all posts

Friday, 4 April 2014

Talend - How to get Last Modified File from a directory using tFileList


Talend - How to get Last Modified File from a directory using tFileList


We often have need to get last modified file from a list of files in a directory. We can use tFileList component to give us list of files sorted (DESC/ASC) from a directory, but for now it does not have feature to restrict to last modified file. 
one possible solution to achieve this is as below

tFileList(sorted DESC by file modified date) ------> tFixedFlowInput (schema - filename, filenumber) ----->tHashOutput

here in tFixedFlowInput filename = file(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"/"+(String)globalMap.get("tFileList_1_CURRENT_FILE")

filenumber = (Integer)globalMap.get("tFileList_1_NB_FILE")

What above will accomplish is get list of all files in the directory with their number/rank - where the file last modified will have file number =1 and next to that will have 2...and so on.

Now on SubJobOK of above tFileList you can have tHashInput which will read from above tHashOutput and filter only row where filenumber==1 - which means the last modified file.

tHashInput (link to tHashoutput) ---->tFilterRow(filenumber==1)------>tLogRow