Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Nawaz26893
Contributor
Contributor

How to retrieve the last 8 files from F

Hello everyone,

I have a Talend job which will do the following:

  1. Grab the most recent 4 files from an FTP server and copy them over to my Talend Server for processing. The files are uploaded one everyday
  2. I am using FTPList to see all the different files and dates associated with them. At this moment. I have used a tLogRow to print out the details from the global variables using Iteratetoflow on my TfileList component.

What is the best way to move the most recent 4 files from my FTP server to Talend Server for processing? Also:

  1. Once the files are in the Talend Server I want to process the files based on todays date. So for instance the filename is XYZ_20210410.csv I would need some type of filemask that would (A) be updated on a daily basis so the filemask would become tomorrow *20210411.csv for instance so it grabs the file dated for today from the 8 files it grabbed initially from the FTP Server.
  2. The file would then be processed and some sql queries would be run to push this into a postgres DB which I have built the job for.
  3. I would then like to iterate over the next 3 files and reprocess them just in case there was an issue to the processing the previous day.

My main issues are how to grab only the last 4 files based on recency and then processing the files by date using a mask on their names as they also have a date. I think I would need to have a logic that is able to store the filenames date and compare it to a global variable whose date gets updated daily and is saved as a context variable and then compare and run the job if they match. Any help would be super appreciated as I am very new to this amazing tool.

Thank you all.

Labels (5)
1 Reply
MS5
Contributor III
Contributor III

Hello,

 

For the current date, you can use function TalendDate.getCurrentDate() that you will store in a global variable.

 

By using components tFTPFileList with a link type "Iterate", you can access all files name by using the global variable CURRENT_FILE (created automatically by the compoent tFTPFileList).

Then you can filter using a tFilter one this filename by comparing the global var that contain current date and the date in the name of the file.

Of course you have to transform each date (current date and file date) to the good format to be sure that the comparision will be ok.

 

You will have something like :

 

tFTPFileList -> (iterate) tFixedFlowInput with one column = CURRENT_FILE globalVar -> tFilter -> your list of 4 files.