August 17, 2023

tFileExist – Docs for ESB 5.x

tFileExist

tFileExist_icon32_white.png

tFileExist Properties

Component family

File/Management

 

Function

tFileExist checks if a file
exists or not.

Purpose

tFileExists helps to streamline
processes by automating recurrent and tedious tasks such as checking
if a file exists.

Basic settings

File Name

Path to the file you want to check if it exists or not.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the Job processing metadata at a
Job level as well as at each component level.

Usage

This component can be used as standalone component.

Global Variables

EXISTS: the result of whether a specified file exists.
This is a Flow variable and it returns a boolean.

FILENAME: the name of the file processed. This is an
After variable and it returns a string.

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio
User Guide.

Connections

Outgoing links (from this component to another):

Trigger: On Subjob Ok; On Subjob
Error; Run if; On Component Ok; On Component Error.

Incoming links (from one component to this one):

Row: Iterate.

Trigger: Run if; On Subjob Ok; On
Subjob Error; On component Ok; On Component Error; Synchronize;
Parallelize.

For further information regarding connections, see
Talend Studio
User Guide.

Log4j

The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User
Guide
.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

n/a

Scenario: Checking for the presence of a file and creating it if it does not
exist

This scenario describes a simple Job that: checks if a given file exists, displays a
graphical message to confirm that the file does not exist, reads the input data in
another given file and writes it in an output delimited file.

Dropping and linking the components

  1. Drop the following components from the Palette onto the design workspace: tFileExist, tFileInputDelimited, tFileOutputDelimited, and tMsgBox.

  2. Connect tFileExist to tFile InputDelimited using an OnSubjobOk and to tMsgBox using
    a Run If link.

    Use_Case_tFileExist.png
  3. Connect tFileInputDelimited to tFileOutputDelimite using a Row
    Main
    link.

Configuring the components

  1. In the design workspace, select tFileExist
    and click the Component tab to define its basic
    settings.

    Use_Case_tFileExist1.png
  2. In the File name field, enter the file path
    or browse to the file you want to check if it exists or not.

  3. In the design workspace, select tFileInputDelimited and click the Component tab to define its basic settings.

    Use_Case_tFileExist3.png
  4. Browse to the input file you want to read to fill out the File Name field.

    Warning

    If the path of the file contains some accented
    characters, you will get an error message when executing your Job. For
    more information regarding the procedures to follow when the support of
    accented characters is missing, see the Talend Installation and Upgrade Guide of
    the
    Talend solution you are using.

  5. Set the row and field separators in their corresponding fields.

  6. Set the header, footer and number of processed rows as needed. In this
    scenario, there is one header in our table.

  7. Set Schema to Built-in
    and click the Edit schema button to
    define the data to pass on to the tFileOutputDelimited component. Define the data present in the
    file to read, file2 in this scenario.

    For more information about schema types, see Talend Studio User
    Guide.

    Use_Case_tFileExist5.png

    The schema in file2 consists of five columns: Num, Ref, Price,
    Quant,
    and tax.

  8. In the design workspace, select the tFileOutputDelimited component.

  9. Click the Component tab to define the basic
    settings of tFileOutputDelimited.

    Use_Case_tFileExist4.png
  10. Set property type to Built-in.

  11. In the File name field, press Ctrl+Space to access the variable list and select the
    global variable FILENAME.

  12. Set the row and field separators in their corresponding fields.

  13. Select the Include Header check box as file2
    in this scenario includes a header.

  14. Set Schema to Built-in
    and click Sync columns to
    synchronize the output file schema (file1) with the input file schema
    (file2).

    Use_Case_tFileExist6.png
  15. In the design workspace, select the tMsgBox
    component.

  16. Click the Component tab to define the basic
    settings of tMsgBox.

    Use_Case_tFileExist7.png
  17. Click the If link to display its properties
    in the Basic settings view.

  18. In the Condition panel, press Ctrl+Space to access the variable list and select the
    global variable EXISTS. Type an exclamation mark before the variable to negate
    the meaning of the variable.

    Use_Case_tFileExist8.png

Saving and executing the Job

  1. Press Ctrl+S to save your Job.

  2. Press F6 or click the Run button in the Run tab to
    execute it.

    Use_Case_tFileExist9.png

A dialog box appears to confirm that the file does not exists.

Click OK to close the dialog box and continue the Job
execution process. The missing file, file1 in this scenario, got written in a delimited
file in the defined place.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x