How to execute tFileCopy/tFileDelete from the tJava component

Five Stars

How to execute tFileCopy/tFileDelete from the tJava component

Hi All,

How can I execute components like tFileCopy and tFileDelete from within a tJava/tJavaFlex component. The idea is I would like to rename/move an input file based on certain conditions. My current sample code looks like below and it is obviously wrong because I don't know the sytnax for calling components from within tJava/tJavaFlex components.

I guess an alternative would be to use the tSystem compont within tJava, but I would run into the syntax problems as well. I am not particular whether I used tSystem or tFileCopy - I just want something that does the job.

**The code in the end code section of a tJavaFlex component:

 

 if (num_rows > 0) {
    tFileCopy( ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")) ,
    context.error_dir + jobName + "/" ((String)globalMap.get("tFileList_1_CURRENT_FILE"))
    );
 }

 

With the above code I get the error:

 

error.png


Accepted Solutions
Ten Stars

Re: How to execute tFileCopy/tFileDelete from the tJava component

I don't think you can invoke other components from the custom code components. What you can do is set variables that are used by conditional trigger links.

All Replies
Ten Stars

Re: How to execute tFileCopy/tFileDelete from the tJava component

I don't think you can invoke other components from the custom code components. What you can do is set variables that are used by conditional trigger links.
Moderator

Re: How to execute tFileCopy/tFileDelete from the tJava component

Hello,

With your requirement, you can use "RunIf" trigger which triggers a subjob or component in case the condition defined is met.

You can add your code in the Condition section. Such as:  Main job-->RunIf(num_rows > 0)-->tFileCopy.

Best regards

Sabrina

 

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads