Add a new column with the name of the folder where it is hosted

Highlighted
Five Stars

Add a new column with the name of the folder where it is hosted

 

I am creating a .csv data import project to a postgresql database. and I want to add a new column that takes the name of the folder where the file is being collected, it is possible to do it, and how can I do it.

 

I am using tFileList to recover the files in the specific folder and save all the files in the same table.

 

please help me

Community Manager

Re: Add a new column with the name of the folder where it is hosted

This is quite an easy requirement to fulfil given you are already using the tFileList. All you need to do is add a tMap component somewhere in the flow after the tFileList. Then add a "folder" column. The folder column, you would simply use to one of these globalMap variables....

 

((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))
Five Stars

Re: Add a new column with the name of the folder where it is hosted

thank you, but with 

((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

i have the name of file data.

 

and with

((String)globalMap.get("tFileList_1_CURRENT_FILEDIRECTORY"))

All directory ex: C:\User\Documents\data\info.

 

i need only the name of folder

 

Community Manager

Re: Add a new column with the name of the folder where it is hosted

Given the example in your last post, would your folder name be "info"? If so, all you need to do is extract "info" from this variable. Some code to do that can be seen below...

String path = "C:\\User\\Documents\\data\\info";

String folder = path.substring(path.lastIndexOf('\\')+1);

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

Best Practices for Using Context Variables with Talend – Part 3

Read about some useful Context Variable ideas

Blog