It is possible to check if multiple files exist using arrays but it is a bit fiddly. I often pass this off to another activity in the pipeline eg Stored Procedure or Notebook activity, depending on what compute you have available in the pipeline (eg a SQL database or Spark cluster). However if you do need to do this in the pipeline this may work for you.
To start off, I have an array parameter with the following value:
Parameter Name |
Parameter Type |
Parameter Value |
pFilesToCheck |
Array |
["json1.json","json2.json","json3.json","json4.json"] |
These are the files that must exist. Next I have a Get Metadata
activity pointing at a data lake folder with the Child Items argument set in the Field List:

This will return some output in this format, listing all the files in the given directory, with some additional information on the execution:
{
"childItems": [
{
"name": "json1.json",
"type": "File"
},
{
"name": "json2.json",
"type": "File"
},
{
"name": "json3.json",
"type": "File"
},
{
"name": "json4.json",
"type": "File"
}
],
"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (Some Region)",
"executionDuration": 0,
"durationInQueue": {
"integrationRuntimeQueue": 1
},
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}
In order to compare the input array pFilesToCheck
(the files which must exist) with the results from the Get Metadata
activity (the files which do exist), we must put them in a comparable format. I use an Array variable to do this:
Variable Name |
Variable Type |
arrFilenames |
Array |
Next is a For Each
activity running in Sequential mode and using the range
function to loop from 0 to 3, ie the array index for each item in the childItems
array. The expression determines the number of items in the Get Metadata
output
which is 0-based. The Items property is set to the following expression:
@range(0,length(activity('Get Metadata File List').output.childItems))
Inside the For Each
activity is an Append
activity which appends the current item from the for each loop to the array variable arrFilenames
. It uses this expression in the Value property:
@activity('Get Metadata File List').output.childItems[item()].name
'@item()' in this case will be a number between 0 and 3 being generated by the range
function mentioned above. Once the loop is complete the array arrFilenames
will now look like this (ie in the same format as the input array):
["json1.json","json2.json","json3.json","json4.json"]
The input array and actual file list can now be compared using the intersection
function. I use a Set Variable
activity with a boolean variable to record the result:
@equals(
length(variables('arrFilenames')),
length(intersection(variables('arrFilenames'),pipeline().parameters.pFilesMustExist)))
This expression compares the length of the array which contains the files which actually exist with the length of the same array joined via the intersection function to the input array of files which should exist. If the numbers match then all the files exist. If the numbers do not match then not all the files exist.