One Star

Get the file name of the tfileInputDelimited

Hi,
I would like to display the file name of a tfileInputDelimited in a tMsgBox.
I try this but this doesn't work : (String)globalMap.get("tFileInputDelimited_1__FILENAME__")

How can I do ?
3 REPLIES
Community Manager

Re: Get the file name of the tfileInputDelimited

Hello
There is not such a global varialbe: (String)globalMap.get("tFileInputDelimited_1__FILENAME__"), so you can't use it directly.
But you can put the file in a folder and use a tFileList component to iterate it. There is a global variable(press Ctrl+Space bar can see all the global variables in text fileds):
((String)globalMap.get("tFileList_1_CURRENT_FILE"))
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Get the file name of the tfileInputDelimited

Ok thx for the answer !
And now if I want to write the rows of the input file in a output file but in replacing the whitespace in the input filename by underscore in the output filename, must I use a routine ?
It works in using a routine but I have to use the currentFilePath and the currentFile like this :
-- In the output FileName --
MyRoutine.replaceFileName(((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")),((String)globalMap.get("tFileList_1_CURRENT_FILE")))
-- My Routine --
public class MyRoutine{
public static String replaceFileName(String path, String fileName) {
return path.replaceAll(fileName,replaceWhitespaceByUnderscore(fileName));
}

public static String replaceWhitespaceByUnderscore(String fileName) {
return fileName.replaceAll(" ","_");
}
}

But is there an easier or more stylish way to do it ?
Community Manager

Re: Get the file name of the tfileInputDelimited

Hello
But is there an easier or more stylish way to do it ?

The tReplace component can archive the same function instead of routine.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business