Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
RA6
Creator
Creator

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.

 

0683p000009LySt.jpg

 

 

0683p000009Ly6y.jpg

 

My tfilelist:

0683p000009LyT3.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?

Labels (4)
1 Solution

Accepted Solutions
RA6
Creator
Creator
Author

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);

 

View solution in original post

9 Replies
fdenis
Master
Master

use tflieCopy

RA6
Creator
Creator
Author

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.

fdenis
Master
Master

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.
RA6
Creator
Creator
Author

@TRF

@xdshi

@rhall

 

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

TRF
Champion II
Champion II

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.

fdenis
Master
Master

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.
RA6
Creator
Creator
Author

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);

 

SR2210
Contributor
Contributor

Hi @Rohit Aftab​ 

 

i'm facing the same issue to change the file extension and i've tried this code in tjava. However, i'm getting error saying that "File cannot be resolved to a type"

 

Did you face the same error before or no? Do you have any idea about this?

 

Thank you

root
Creator II
Creator II

Please try importing "java.io.File"