How to use the Get Metadata activity in Azure Data Factory
The Get Metadata activity in Azure Data Factory lets you ask your storage "does this file exist? how big is it? what files are in this folder?" before you copy anything. Knowing how to use the Get Metadata activity in Azure Data Factory prevents pipelines that break halfway through because the source has not landed yet, and it opens the door to dynamic pipelines that react to what they find.
Prerequisites
- An Azure subscription with an Azure Data Factory instance already created.
- An Azure Data Lake Storage Gen2 (or Blob Storage) account with a sample folder, for example
raw/vendas/. - A linked service pointing to that storage, with read permissions.
- Basic familiarity with ADF Studio: pipelines, datasets and activities.
Step 1: Create the dataset for the source folder
In ADF Studio, go to Author > Datasets > New dataset and pick Azure Data Lake Storage Gen2 with the DelimitedText format. On the Connection tab, set the container and the folder path, but leave the file name empty when you want to inspect the whole folder.
Tip: create two datasets — one pointing at the folder (ds_pasta_vendas) and one at a specific file (ds_ficheiro_vendas). The Get Metadata activity returns different fields depending on whether the target is a folder or a file.
Step 2: Add the Get Metadata activity to the pipeline
Create a new pipeline (pl_metadata_demo), drag the Get Metadata activity from the General group and name it GetMetadataPasta. On the Dataset tab, select ds_pasta_vendas.
Step 3: Choose the fields in the Field list
Still on the Dataset tab, click New inside the Field list and add the fields you want to read. The most useful ones are:
exists— returns true or false; works for both files and folders.childItems— lists the contents of a folder (folders only).itemNameanditemType— name and type (File or Folder).sizeandlastModified— size in bytes and last modified date (files only).
In JSON, the activity looks like this:
{
"name": "GetMetadataPasta",
"type": "GetMetadata",
"typeProperties": {
"dataset": { "referenceName": "ds_pasta_vendas", "type": "DatasetReference" },
"fieldList": [ "exists", "childItems" ],
"storeSettings": { "type": "AzureBlobFSReadSettings" },
"formatSettings": { "type": "DelimitedTextReadSettings" }
}
}
Step 4: Validate that the source exists with If Condition
Add an If Condition activity next and connect it to Get Metadata through the green (Success) arrow. In the expression, read the output of the previous activity:
@activity('GetMetadataPasta').output.exists
Put the Copy Data activity that loads the data in the True branch. In the False branch, put a Fail activity with a clear message, something like "The raw/vendas folder has not received any files yet". The pipeline no longer blows up with a cryptic error — it fails in a controlled way.
Step 5: Loop through the folder files with ForEach
The childItems field returns an array of objects with name and type. Pass that array to a ForEach activity:
Items: @activity('GetMetadataPasta').output.childItems
Inside the ForEach, on the Copy Data source dataset:
parameter nomeFicheiro = @item().name
The pipeline now copies every file it finds, with no hard-coded names. To process only CSV files, add a Filter activity before the loop with the condition @endswith(item().name, '.csv').
Common error: the activity fails instead of returning false
If Get Metadata throws "The required Blob is missing" instead of returning exists: false, you almost certainly forgot to include exists in the Field list. With that field present, the activity answers false instead of raising an error — which is exactly what lets you validate the source without breaking the pipeline.
Verify the result
Click Debug and, in the Output pane, click the glasses icon on the GetMetadataPasta activity. You should see JSON similar to this:
{
"exists": true,
"childItems": [
{ "name": "vendas_2026_07.csv", "type": "File" },
{ "name": "vendas_2026_06.csv", "type": "File" }
]
}
If childItems comes back empty, check the folder path and the linked service permissions — the Data Factory managed identity needs the Storage Blob Data Reader role on the storage account.
Conclusion
Get Metadata + If Condition + ForEach is the foundation of almost every dynamic Azure Data Factory pipeline: check, decide, iterate. The natural next step is to combine the lastModified field with a watermark variable so you copy only the files that are new since the last run. What check would you like your pipeline to run before the copy starts?