The Expression for extracting date: @substring(item().name, 5, 8) item()
represents the current file being processed in the ForEach
loop.
If you have an array of filenames, loop through them with the ForEach activity.
Inside the loop, use the extracted date to compare with a reference date stored in the varReferenceDateTime variable.
If the extracted date is more recent than the reference date, update the varReferenceDateTime variable and the fileNameToBeProcessed variable.
Here is demonstration by a community expert: Azure Data Factory - Copy the latest file with DATE PART to Folder using AZURE FUNCTIONS.
Use the "Get Metadata" activity in ADF to retrieve the list of filenames from the ADLS container.
{
"name": "GetMetadataAndCopy",
"properties": {
"activities": [
{
"name": "GetMetadata",
"type": "GetMetadata",
"linkedServiceName": {
"referenceName": "Your_ADLS_LinkedService",
"type": "LinkedServiceReference"
},
"typeProperties": {
"dataset": {
"referenceName": "Your_ADLS_Dataset",
"type": "DatasetReference"
},
"fieldList": ["childItems"]
}
},
{
"name": "ForEach",
"type": "ForEach",
"typeProperties": {
"items": {
"value": "@activity('GetMetadata').output.childItems",
"type": "Expression"
},
"activities": [
{
"name": "CopyData",
"type": "CopyData",
"typeProperties": {
"source": {
"type": "BlobSource"
},
"sink": {
"type": "SqlSink"
},
"input": {
"referenceName": "Your_Input_Dataset",
"type": "DatasetReference"
},
"output": {
"referenceName": "Your_Output_Dataset",
"type": "DatasetReference"
}
}
}
]
}
}
]
}
}