[resolved] current_file in tFTPFileProperties

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

All Replies
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
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
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
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
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
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)
One Star

Re: [resolved] current_file in tFTPFileProperties

Thank you shong ! This is what I needed Smiley Happy