[resolved] Iterate file list and rename with excel lookup

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?

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

All 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!
Four Stars

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

hi sorry for dig up post 

I use the same job but tFilcopy dont copy (and doesn't rename too) files.

I have an error : 

 

Exception in component tFileCopy_1 (testcmis)
java.lang.NullPointerException
	at java.io.File.<init>(File.java:317)
	at renommerfichier.testcmis_0_1.testcmis.tFileList_1Process(testcmis.java:4832)
	at renommerfichier.testcmis_0_1.testcmis.runJobInTOS(testcmis.java:5364)
	at renommerfichier.testcmis_0_1.testcmis.main(testcmis.java:5213)

I have this error only with tfilecopy at the end, if I use toutputexcel my inner join works good in tmap with tfilelist name file ...