How to get file name

One Star

How to get file name

Hi,
I want to upload a csv file into sql server table. I need get the file name and use the file name in the job. The file name pattern is "nl_accounts_yyyy.csv". I want to exact the 'yyyy' and store it in table. how i can do that?
thanks!
One Star

Re: How to get file name

you can use a tfilelist for that, even if you iterate only on one file
put a tfilelist on your job plug iterations on on a tjavarow
in the tjavarow press <ctrl>+<space> it will propose a list of variables choose the one you want from tfilelist
One Star mpa
One Star

Re: How to get file name

Yang,
I would do the following.
tFileList --> tFixedFlowOutput --> tMssqlOutput
Following code in tFixedFlowedInput:
StringHandling.RIGHT(StringHandling.LEFT(((String)globalMap.get("tFileList_1_CURRENT_FILE")),StringHandling.LEN(((String)globalMap.get("tFileList_1_CURRENT_FILE")))-4),4)

If you want to load the file in your database and have the year in an extra column you can do the following:
tFileList --> tFileinputdelimited--> tMap --> tMssqlOutput
In the extra column in the output part of the tMap you can put the same code from the tfixedflowinput. Every record will then have the year of the file in an extra column.
See attached screenshots.
Regards
Highlighted
One Star

Re: How to get file name

thanks for reply!

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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

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