kira_22
kira_22

Reputation: 15

Filter out file using wildcard path azure data factory

I am working on a pipeline and while using the copy activity, in the file wildcard path I would like to skip a certain file and only copy the rest. Is there an expression for that ? I know that a * is used to match zero or more characters but in this case, I would like an expression to skip a certain file.

I am still very new to adf

Thank you.

Upvotes: 1

Views: 18458

Answers (2)

NiharikaMoola
NiharikaMoola

Reputation: 5074

In Get Metadata activity, we can add an expression to get files of a specific pattern. I tried to write an expression to exclude files but was not successful.

Below is what I have tried to exclude/skip a file from the list of files to process.

Files in the Input folder:

enter image description here

Azure Data Factory Pipeline:

  1. In my Input folder, I have 2 types of files .csv and .txt. You can add expression in the filename to get the only “.csv” files using Get Metadata activity

Filename Expression: *.csv

enter image description here

Get Metadata activity Output:

enter image description here

  1. Connect filter activity to Get Metadata activity output to exclude a file (or files of specific pattern) from the list of files from child items.

Filter activity Settings:

Items: @activity('Get Metadata1').output.childitems

Condition: @not(contains(item().name,'1c56d6s4s33s4_Sales_09112021.csv'))

enter image description here

Output of Filter activity:

enter image description here

  1. Process each value of filter activity using foreach activity.

Items: @activity('Filter1').output.Value

enter image description here

This loop runs 2 times as there are only 2 files that returned from filter activity output after excluding a file.

Upvotes: 0

Joel Cochran
Joel Cochran

Reputation: 7728

I'm not sure you can use the wildcard feature to skip a specific file, unless all the other files follow a pattern the exception does not follow.

One approach would be to use GetMetadata to list the files:

enter image description here

Note the inclusion of the "ChildItems" field, this will list all the items (Folders and Files) in the directory.

Next, use a Filter activity to reference only the files:

enter image description here

Items code:

@activity('Get Child Items').output.childItems

Filter code:

@and(equals(item().type,'File'),endswith(item().name,'.txt'))

NOTE: This example filters to Files with a .txt extension. You would change this code to meet your criteria.

Finally, use a ForEach to loop over the now filtered items. The ForEach would contain our COPY activity for each individual item:

enter image description here

Upvotes: 6

Related Questions