0

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

  • if two files are existing proceed to the True condition databricks notebook. If one is not present, will proceed to False condition databricks notebook.

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.

9
  • Are you getting any error? Commented Sep 10, 2024 at 11:26
  • no error but no result as well. after successful run of if condi activity, nothing happens. Commented Sep 10, 2024 at 12:09
  • The IF condition has to be True, False, or the activity has to Fail. Which one is the case in your example? Commented Sep 10, 2024 at 14:14
  • My example is once met, the True condition will run. Commented Sep 10, 2024 at 14:47
  • I understand what you want to happen, but you said "Nothing happens", which can't be correct. Commented Sep 10, 2024 at 14:59

2 Answers 2

0

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)
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thank you so much. This solved my problem for a week. I tried the 1st approach, used @and(contains(string(activity('Get Metadata1').output.childItems),concat('DA_12345','.pdf')), contains(string(activity('Get Metadata1').output.childItems),concat('DA_12345','.xlsx'))). I just wanna know what if idk the filenames, i tried just @and(contains(string(activity('Get Metadata1').output.childItems),concat('DA_','.pdf')), contains(string(activity('Get Metadata1').output.childItems),concat('DA_','.xlsx'))). but the result is not my expectation.
Hi, I already get the right expression. @and(contains(string(activity('GetFileList_MFT').output.childItems),'.pdf'), contains(string(activity('GetFileList_MFT').output.childItems),'.xlsx'))
I thought to give the same. Good to know that you have solved yourself : ).
0

Thanks to Rakesh Govindula for the solution. I tried this one if I know the filenames from sftp:

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

This is also working if you just want to check the files if contains specific string on the files:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.