One Star

[resolved] Iterate file list and rename with excel lookup

I am trying to read a directory of files and rename them to a different filename. An excel file with 2 columns, oldfilename and newfilename, will act as a lookup for the new renamed files. While iterating through the filelist logic it would match current filename in list to oldfilename in excel and than using rename in filecopy replace with corresponding newfilename in excel.
using tfilelist, tfileinputexcel, tfilecopy and some lookup logic (tJava or some other component) components, how would I construct a design model using row and trigger connectors?
Are there any examples to reference that does this? Has anyone done this before?
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] Iterate file list and rename with excel lookup

Hi
Try this:
tFileList_1--iterate--tFixedFlowInput--main--tMap--main(out1)--tFlowToIterate--tFileCopy
                                                                  |
                                                             lookup
                                                                  |
                                                         tFileInputExcel
on tFixedFlowInput: generate the current file name, define one column on the schema, and set its value as:
((String)globalMap.get("tFileList_1_CURRENT_FILE"))

on tMap, do a inner join or left outer join based on current file name, out the new file name.
tFileCopy, set the File name with current file path:
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

Check the 'Rename' box, and set its new file as:
(String)globalMap.get("out1.newfilename")

//newfilename is the column name defined in the output table on tMap.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
2 REPLIES
Community Manager

Re: [resolved] Iterate file list and rename with excel lookup

Hi
Try this:
tFileList_1--iterate--tFixedFlowInput--main--tMap--main(out1)--tFlowToIterate--tFileCopy
                                                                  |
                                                             lookup
                                                                  |
                                                         tFileInputExcel
on tFixedFlowInput: generate the current file name, define one column on the schema, and set its value as:
((String)globalMap.get("tFileList_1_CURRENT_FILE"))

on tMap, do a inner join or left outer join based on current file name, out the new file name.
tFileCopy, set the File name with current file path:
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

Check the 'Rename' box, and set its new file as:
(String)globalMap.get("out1.newfilename")

//newfilename is the column name defined in the output table on tMap.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Iterate file list and rename with excel lookup

Worked perfectly. Used 'Inner Join' on Join Model in tmap to prevent subsequent run errors. Thank you for this contribution!