azure-data-factorysftp

Check if two files are existing in SFTP using ADF


I have two files (xlsx & pdf) in sftp folder. These are the requirements I need to complete:

Edited: This is what I tried first. Used get metadata and If condition activity. get metadata activity

If condition activity expression: If condition activity expression

The two files are existing so I am expecting to receive the notebook in True condition, however, notebook in False condition is running.


Solution

  • I have tried your expression, and I got similar results.

    enter image description here

    Here, in your expression, you are checking .xlsx and .pdf strings existing or not in the array. But these are only substrings of each item in the Child items array. The contains() for an array only gives true when the given total string is in the array which is not in your case. To achieve your requirement, try the below approach.

    First, in the Get meta data activity, give the path till only your source folder. Don't include the file name. Add Child items property.

    enter image description here

    As you already know the file name without extension, now use the below expression in the if activity.

    @and(contains(string(activity('Get Metadata1').output.childItems),concat('DA_12345','.pdf')), contains(string(activity('Get Metadata1').output.childItems),concat('DA_12345','.xlsx')))
    

    This expression first converts the total child items array into a string and then checks whether both file names are in the string or not. I have given the file names as it is in the expression, you can use your parameters.

    enter image description here

    Now, it will work as expected.

    enter image description here

    You can also try exists option in the Get meta data activity by giving the file name. This option gives true if the given file name exists in the given folder and false if not exists.

    enter image description here

    But you need to use two Get meta data activities for this, in which one is for .pdf and another is for .xlsx. After both activities, you can directly use this expression in the if activity.

    @and(activity('Get Metadata1').output.exists,activity('Get Metadata2').output.exists)