Five 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

1 ACCEPTED SOLUTION

Accepted Solutions
Eleven Stars

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.

Rilhia Solutions
1 REPLY
Eleven Stars

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.

Rilhia Solutions