How to get file names, size, row count and send it to email by using Java components or can we achieve without java components
You can use the tFileProperties for everything but number of rows. For number of rows you will need to read the files and count them.
Actually my requirement is I have some set of different files in one (reject files)folder. I have to sent an email like filename, filesize and no.of records in file. Can you help me with this requirement.
Use 'tFileProperties' component to get the file name, size, permission, etc.
And to get the number of rows from file use 'tFileRowCount' component and link this using onSubJobOk to tJava/ tJavaRowcomponent. In tJava/ tJavaRow component use below expression to get the row count and store it into a context variable.
context.FILES_RECORDS = ((Integer)globalMap.get("tFileRowCount_1_COUNT"));
Here I'm trying to replicate the solutions. Below is the screenshot of the Job Design.
Try this and let me know if this will work for you.
Also, Give kudos if this work for you.
You can use the method shown, but will have to use some basic Java String manipulation to build up the details you want for each file (the email message) and append to that for each file. You should be able to do that in the tJavaRow quite easily.
Something like this (you will have to experiment with this and tweak it yourself).....
context.Message = context.Message+"File: "+input_row.basename+"\r\n"+ "File Path: "+input_row.abs_path+"\r\n"+ "File Size: "+input_row.size+"\r\n\r\n";
You then just use the context.Message in your send mail component.
Have you tried reproducing the job that @vaibsVB suggested? If not, do that first. If so, replace the tJavaRow code with mine (after configuring a new context variable for Message) and see what you get.
Can you tell us what you did so that others can benefit from this question in the future?
I have followed the above one @vaibsVB's model and gave your context.email(message) in tjavarow it is working
Sorry for reaching late.
@im_arod Glad part of my solution work for you.
@rhall_2_0 Thanks for giving inputs.
In order to get all files from the folder, I tried another approach try this if it works for you.
And also suggest improvements also.
tFileList_3 and tFileProperties_2 settings are same as previous example.
At tIterateToFlow_1 here are the settings:
At tDenormalize_1 here are the settings:
Make note, in above Delimiter setting I purposefully kept the ", ".
And you will get desired output i.e. FileNames from the folder in list format. You can store this filename list into context and use in Mail Component.
Introduction to Talend Open Studio for Data Integration.
Practical steps to developing your data integration strategy.
Create systems and workflow to manage clean data ingestion and data transformation.