Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
tvsr984
Contributor
Contributor

[resolved] Get file name without extension

Hi,
Will it be possible to get the file name alone with out the extension of file.
Example: KPPADF015-D00000-G0017700.xml
After processing the file at the output i want KPPADF015-D00000-G0017700_Text.txt
If i use (String)globalMap.get("tFileList_2_CURRENT_FILE")+"_Text"+".txt"
i am getting KPPADF015-D00000-G0017700.xml_Text.txt
I want the above output with out the file extension i.e,, KPPADF015-D00000-G0017700_Text.txt
For getting this i am using StringHandling.LEFT(((String)globalMap.get("tFileList_2_CURRENT_FILE")),25)+"_Text"+".txt"
The problem with the above approach is if the file name length is more than 25 letters it will not work. Is there any talend method to handle this dynamically with respect to file name alone with out extension.
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Change the code to:
((String)globalMap.get("tFileList_2_CURRENT_FILE")).substring(0,((String)globalMap.get("tFileList_2_CURRENT_FILE")).indexOf("."))+"_Text.txt"

View solution in original post

5 Replies
Anonymous
Not applicable

Hi
Try this expression:
(String)globalMap.get("tFileList_2_CURRENT_FILE").substring(0, (String)globalMap.get("tFileList_2_CURRENT_FILE").indexOf(".") )+"_Text.txt"
tvsr984
Contributor
Contributor
Author

Hi,
It shows the following error
compilation problems: 
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
The method substring(int, String) is undefined for the type Object
The method indexOf(String) is undefined for the type Object
at gale.test_it_0_1.TEST_IT.tFileList_5Process(TEST_IT.java:563)
at gale.test_it_0_1.TEST_IT.runJobInTOS(TEST_IT.java:3132)
at gale.test_it_0_1.TEST_IT.main(TEST_IT.java:2982)
Anonymous
Not applicable

Change the code to:
((String)globalMap.get("tFileList_2_CURRENT_FILE")).substring(0,((String)globalMap.get("tFileList_2_CURRENT_FILE")).indexOf("."))+"_Text.txt"
tvsr984
Contributor
Contributor
Author

Thanks a lot!!. It works perfectly.
Also i am able to acheive the same result using the following
((String)globalMap.get("tFileList_2_CURRENT_FILE")).replaceAll(".xml", "")
Either way it works!!!
Anonymous
Not applicable

Great, thanks for your feedback!