Search code examples
talendfile-management

Move current day's latest files using Talend


I have a job in Talend which will connect to a folder and look for the current day's files (based on the name i.e. 20150928_MyFile, 20150928_MySecondFile and 20150928_MyThirdFile ) and will move these files to some other folder. I have used below flemask to look for today's file but this way Talend is moving all the files for today's date but I want it to move only the latest file of today's date for(20150928_MyFile, 20150928_MySecondFile and 20150928_MyThirdFile) each file to be moved. I have used the below FILE MASK -

((String)TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate())) + "*.CSV"

Thanks a lot in advance!!

enter image description here


Solution

  • You cant trust the current date based mask, because it not necessary to have a file in the NOW moment, but you can use tFileList to get last modified time and in each iteration, get the max last modified time:

    tFileList-----(iterate)------tJavaRow
        |
        |
    (OnSubJobOk)
        |
        .. [the rest of the job]
    
    • tFileList can iterate over folder and sort the files by modifiction time.
    • tJavaRow get only the first file, use a global variable or context variable to save it.