[resolved] current_file in tFTPFileProperties

Highlighted
One Star

[resolved] current_file in tFTPFileProperties

Hello !
In order to find the most recent file contained in a folder on a FTP server, I'd like to use to tFTPFileProperties on each file of the folder.
I have a tFTPFileList in which my directory is "/home/folder"
I've linked the tFTPFileList to a tFTPFileProperties in which I wanted to get all the file names using "((String)globalMap.get("tFTPFileList_1_CURRENT_FILE"))"
However "((String)globalMap.get("tFTPFileList_1_CURRENT_FILE"))" is returning me "/home/folder/filename1" instead of just "filename1" and I don't know how to get the file name without the file path.
( "((String)globalMap.get("tFTPFileList_1_CURRENT_FILEPATH"))" is giving me "/home/folder//home/folder/filename1" )
Is this a bug ? How can I get the file name alone ? Smiley Happy

Accepted Solutions
Highlighted
Community Manager

Re: [resolved] current_file in tFTPFileProperties

Hello
It is not a bug, the return value is a absolute path of file.
How can I get the file name alone ?

tFTPFileList --iterate-->tFTPFileProperties
Output the basename column of tFTPFileProperties, that's the file name alone.
Best regards

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

View solution in original post


All Replies
Highlighted
Community Manager

Re: [resolved] current_file in tFTPFileProperties

Hello
It is not a bug, the return value is a absolute path of file.
How can I get the file name alone ?

tFTPFileList --iterate-->tFTPFileProperties
Output the basename column of tFTPFileProperties, that's the file name alone.
Best regards

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

View solution in original post

Highlighted
One Star

Re: [resolved] current_file in tFTPFileProperties

Thank you shong ! However, my problem was concerning the tFTPFileProperties settings as I wanted to put the filename in the "file" field.
Can you tell me how I can do this ? Smiley Happy
Highlighted
Community Manager

Re: [resolved] current_file in tFTPFileProperties

Hello
my problem was concerning the tFTPFileProperties settings as I wanted to put the filename in the "file" field.

You should put the file path in the file filed of tFTPFileProperties, if you link a tFTPFileList to tFTPFileProperties, the file path shoud be set as:
((String)globalMap.get("tFTPFileList_1_CURRENT_FILEPATH"))
why would you like set it as the file name only?
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: [resolved] current_file in tFTPFileProperties

I don't understand because here are my results according to my settings when using only a tFTPFileProperties linked to a tLogRow :
remote directory : "."
file : "/home/folder/filename.txt"
result : |||||

remote directory : "/home/folder/filename.txt"
file : "."
result : Exception in component tFTPFileProperties_1
com.enterprisedt.net.ftp.FTPException: Unable to determine if file '/home/folder/filename.txt/.' exists.

remote directory : "/home/folder/"
file : "filename.txt"
result : /home/folder/filename.txt|/home/folder/|filename.txt|4023|1241444237000|Mon May 04 15:37:17 CEST 2009
So it seems to me that I really need to separate the filename from the filepath to get what I want... Is there something I don't understand here ? Smiley Happy
Highlighted
Community Manager

Re: [resolved] current_file in tFTPFileProperties

Hello
I understand you now, you have set the file path in remote directory. Now, you can get the file name like this:
((String)globalMap.get("tFTPFileList_1_CURRENT_FILE")).substring(((String)globalMap.get("tFTPFileList_1_CURRENT_FILE")).lastIndexOf("/")+1)

Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Highlighted
One Star

Re: [resolved] current_file in tFTPFileProperties

Hello Augustine,
you can get only the filename with this expression in a Tmap :
row.basename.substring(row.basename.lastIndexOf("/")+1)
Highlighted
One Star

Re: [resolved] current_file in tFTPFileProperties

Thank you shong ! This is what I needed Smiley Happy

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

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