Copy a the most recent file from one directory to another.

One Star

Copy a the most recent file from one directory to another.

Hi All, 
I have an issue where I am required to copy the most recent version of a file from one directory to another if the file has been created. Due to requirements, I have to append today's date to the end of each file for reference in a CRM. E.g. "E:/BNSF Integration/Integration Logging/Success Files/Success" + "-" + TalendDate.getDate("yyyy-MM-dd") + ".csv"
Would anyone be able to explain how I would copy the most recent file (with today's date), whilst maintaining the original?
Thanks!
Moderator

Re: Copy a the most recent file from one directory to another.

Hi,
Here is a component TalendHelpCenter:tWaitForFile which is used to put the component connected with it in waiting state. It then triggers that component when the defined file operation occurs in the specified directory.
For your job requirement, you can design your job like:twaitforfile(a file is created)-->tfilecopy(copy file into a target directory).
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Copy a the most recent file from one directory to another.

Hi Sabrina, 
Thank you, that is an excellent idea. However, I still have the issue whereby I need to select the file with today's date each day the integration runs. Having looked at the tFileCopy, it seems that you have to provide the file path. That path will change each day as the respective day's date is appended to the file name upon creation. All the files have to remain in the source directory as well.
Thanks
Chris