Hi,
I am unable to get Date from a file name to use in tmap expression editor.
Attached is my Job design and tMap editor view.
1) The tFileRowCount input file name is like "Data_f.cat.fy16.detail.201602.txt". Now I need to read the date part which is "201602" in this case (YYYYMM) and pass it to the "ExtractDate" expression in the tMap expression editor on the output file. For now I've hardcoded "ExtractDate=201602" as you can see in the attached image, but as per the requirement it should read the date from the actual date file name, which is given as input for tFileRowCount in the current job.
2) Is there any way to achieve with and/or without tJava related components
Let me know if I am not very clear about the requirement.
thank you for your time.
Hi, thank you for quick reply.
I've already managed to get the file name using tFileList. But what I could not figure out was how to get only date (201602) from
"Data_f.cat.fy16.detail.201602.txt" and use it in tMap
Since you do not know the filename, I am assuming that you are using the tFileList component to pass the filename to the component you are using to read it. If you aren't, then you probably should be. If you tFileList is called tFileList_1, the way to get the filename is to use this code....
Hi, thank you for quick reply.
I've already managed to get the file name using tFileList. But what I could not figure out was how to get only date (201602) from
"Data_f.cat.fy16.detail.201602.txt" and use it in tMap
You can use Java String functions "substring" and "indexOf" to do this. You know that the date comes just before ".txt" and you know it is 6 characters. That is all you need.
Hi ..
I have used the java string function as below, to get the date from the file name "
Data_f.cat.fy16.detail.201602.txt" :
"ExtractDate="+(((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(23,((String)globalMap.get("tFileList_1_CURRENT_FILE")).indexOf(".txt")))
I've used 23 as that is the number of characters before 201602 in the file name, and then I got the output as desired which is ExtractDate=201602.
but, what if the number of characters before the date in the filename changes or varies?
PS: Sorry, I'm not from core development / programming background.
You use "indexOf" to work out where the ".txt" is in the String. Then you know that the start of your date is 6 characters before that position. You then have your beginning and end position.
I might sound too dumb but ..
what do I pass instead of 23? how do I tell to get last 6 digits (before .txt) instead of telling to ignore first 23 characters?
thank you very much .. it looks complete now .. Got It
where can I learn or what key words shall I use to search google .. to learn similar java (or string or any other) related functions to use in Talend .. not to learn complete Java.
thanks again