Dynamic FileName Change

Highlighted
Six Stars

Dynamic FileName Change

Hi Team

 

I have a simple Scenario

Using tFileList  i am reading a list of files and converting them to excel formats

while doing this process i want target file name to same as source file name but with Excel extension

How can this be achived,

I am using Using "((String)globalMap.get("tFileList_1"))" to get the filname,but i am getting file name along with source extension.

I am attaching the screenshot here with

 

Please help me out how this can be done

 

Thanks in advance

Deepthi

Deepthi


Accepted Solutions
Highlighted
Community Manager

Re: Dynamic FileName Change

You just need to use a tiny bit of Java. It is probably better to turn this into a routine so that your code doesn't look messy in your job, but this is how you would do without a routine....

 

((String)globalMap.get("tFileList_1")).substring(0,((String)globalMap.get("tFileList_1")).indexOf('.'))+".xls"

 

As a routine it might look like this......

public static String replaceFileExtension(String filename, String extension){
     String returnVal = filename;
     
    if(filename!=null && filename.indexOf('.')>-1){
           returnVal = filename.substring(0, filename.indexOf('.'))+"."+extension;
    }
    return returnVal;
}

You would use the above like below....

 

replaceFileExtension(((String)globalMap.get("tFileList_1")), "xls")

 

#I should point out that I have written this freehand so there may be a couple of tweaks required.

View solution in original post


All Replies
Highlighted
Community Manager

Re: Dynamic FileName Change

You just need to use a tiny bit of Java. It is probably better to turn this into a routine so that your code doesn't look messy in your job, but this is how you would do without a routine....

 

((String)globalMap.get("tFileList_1")).substring(0,((String)globalMap.get("tFileList_1")).indexOf('.'))+".xls"

 

As a routine it might look like this......

public static String replaceFileExtension(String filename, String extension){
     String returnVal = filename;
     
    if(filename!=null && filename.indexOf('.')>-1){
           returnVal = filename.substring(0, filename.indexOf('.'))+"."+extension;
    }
    return returnVal;
}

You would use the above like below....

 

replaceFileExtension(((String)globalMap.get("tFileList_1")), "xls")

 

#I should point out that I have written this freehand so there may be a couple of tweaks required.

View solution in original post

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog