Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to change file name / extension for number of files?

Hello community 0683p000009MACn.png
I need your advice for the following problem:
I have a job that gets files from remote FTP server.
I need to archive these files and then change file names / extensions for originally downloaded files. (see job print screens)
Naming of source files is done according to the following mask: cccccc_yyyy-MM-dd.dat
I need to keep only first 6 characters and .dat should be changed to .csv
My idea was to use tFileCopy with Rename to change file name/extension. But it fails...
Looks like I can't use Talend StringHandling system routine to build destination filename
Like LEFT(((String)globalMap.get("tFileList_1_CURRENT_FILE")),6)+".csv"
The warning/error is:
Warning! Some errors exist in jobs.
The method LEFT(string, int) is undefined for the type get_files_from_ftp
Any idea how can I change file name / extension for number of downloaded files?
Labels (2)
7 Replies
Anonymous
Not applicable
Author

Hello
The destination name should be:
StringHandling.LEFT(((String)globalMap.get("tFileList_1_CURRENT_FILE")),6)+".csv"

Best regards

shong
Anonymous
Not applicable
Author

Thank you Shong. Now it works...
Anonymous
Not applicable
Author

hi shong!!!

Ur solution seem to solve my problem..
but i need to add the counting number in between in file name..
for example
StringHandling.LEFT(((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")),6)+ ".txt"
this returns as 'sample.txt'
but i want it as 'sample_001.txt'
001 should be the file count that retrieves per day..
Thank u so much!!!!
Anonymous
Not applicable
Author

Can someone please help out with the solution to this last issue/problem.

 

Thanks

Anonymous
Not applicable
Author

Hi,

 

tFileList_1_NB_FILE parameter can give the file count under a folder. You can store the details in a context variable if needed for later use such as appending the number to file extension.

 

Warm Regards,

 

Nikhil Thampi

 

TRF
Champion II
Champion II

If your job run on a daily basis, you can use the following:
StringHandling.LEFT(((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")),6) + "_" + StringHandling.RIGHT("000"+(Integer)globalMap.get("tFileList_1_NB_FILE"),3) + ".txt"

If it run more than once per day, you need to associate a counter to a context variable which will be retrieve from a properties file each time the job will start. Then you will have to change the expression into the tFileCopy like this:
StringHandling.LEFT(((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")),6) + "_" + StringHandling.RIGHT("000"+((Integer)globalMap.get("tFileList_1_NB_FILE")+context.Counter),3) + ".txt"

Have a look at tContextLoad / tContexDump component to know how to set a context variable from a file (with help of tFileInputDelimited) and how to store it into a file (with help of tFileOutputDelimited).
You will need also an other context variable to count the job runs and decide when to reset the all the counters to 1 (for example, if the job runs every hour, reset should occur when the run counter reach the value of 25).
Hope this helps.
Anonymous
Not applicable
Author

 

Actually iam using file name as :-

"D:/Talend/CSV_Output/PrimarySalesAggData_AnalysisTeam_"+TalendDate.formatDate("yyyy-MM",TalendDate.getCurrentDate())+".csv" (it is working for me)

It is working up to this month if iam running this job toady i want the file name as previous month likePrimarySalesAggData_AnalysisTeam_201908

How to achieve this and while extracting to s3 iam giving key as

"PrimarySalesAggData_AnalysisTeam_"+TalendDate.formatDate("yyyy-MM",TalendDate.getCurrentDate())"

 but iam getting error as string literal is not properly close by double quotes.

can someone help me