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
Twelve 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.

Twelve 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

Fifteen Stars TRF
Fifteen 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
Twelve 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);

 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now