Changing a file extension from list

Seven Stars

Changing a file extension from list

Hello,

 

I have a directory which contain several xml files and 1 file with (.tmp) extension.

I am trying to rename or replace the toTest.tmp to toTest.xml using a tfilelist and a tjava.

 

Capture6.JPG

 

 

capture4.JPG

 

My tfilelist:

Capture5.JPG

 

My tjava codes:

((String)globalMap.get("tFileList_3_CURRENT_FILE")).replace(((String)globalMap.get("tFileList_3_CURRENT_FILEEXTENSION")), "xml");

The job is ending without error but the file renaming is not taking place.

 

Can you suggest please?


Accepted Solutions
Seven Stars

Re: Changing a file extension from list

I found a solution:

 

// File (or directory) with old name
File oldfile = new File(((String)globalMap.get("tFileList_4_CURRENT_FILEPATH")));

// File (or directory) with new name
File newfile = new File(((String)globalMap.get("tFileList_4_CURRENT_FILEPATH")).replace(((String)globalMap.get("tFileList_4_CURRENT_FILEEXTENSION")), "xml"));

// Rename file (or directory)
boolean success = oldfile.renameTo(newfile);

 


All Replies
Eleven Stars

Re: Changing a file extension from list

use tflieCopy

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Seven Stars

Re: Changing a file extension from list

Normally, in my case, i cannot use tfilecopy.

 

Can you please advice how can i do this achieve this using tfilelist and tjava please?

 

Thank you.

Eleven Stars

Re: Changing a file extension from list

using tjava is not the best way.
using tjava is like coding in java.
talend is easy to update if it's visual.

if you want to use tjava go to a java forum.

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Seven Stars

Re: Changing a file extension from list

@TRF

@xdshi

@rhall_2_0

 

Since, there is a component in talend named "tjava", i have tried to use it.
I have posted my job example in the previous post. Can someone tell me what is wrong please?

 

Thank you

Forteen Stars TRF
Forteen Stars

Re: Changing a file extension from list

You tJava seems incomplete and as mentionned by @fdenis this is not the best way as soon as you have a component to do what you expect.


TRF
Eleven Stars

Re: Changing a file extension from list

globalMap.put("newFileName",((String)globalMap.get("tFileList_3_CURRENT_FILE")).replace(((String)globalMap.get("tFileList_3_CURRENT_FILEEXTENSION")), ".xml");

but tjava is to use only if you cannot do by an other way.

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Seven Stars

Re: Changing a file extension from list

I found a solution:

 

// File (or directory) with old name
File oldfile = new File(((String)globalMap.get("tFileList_4_CURRENT_FILEPATH")));

// File (or directory) with new name
File newfile = new File(((String)globalMap.get("tFileList_4_CURRENT_FILEPATH")).replace(((String)globalMap.get("tFileList_4_CURRENT_FILEEXTENSION")), "xml"));

// Rename file (or directory)
boolean success = oldfile.renameTo(newfile);