I have getmetadata to get the folder metadata in a container and loop over each folder and get metadata in each folder. now since nested foreach is not allowed how can i get the childitems which are filenames inside this for loop and then do a dataflow

Jayanta Madhab Barman 20 Reputation points
2025-06-18T12:33:52.7666667+00:00

I have getmetadata to get the multiple folders metadata in a container and loop over each folder and get metadata of files in each folder inside this for loop. now since nested foreach is not allowed how can i get the childitems which are filenames inside this for loop and so that i can pass foldername and filename as parameters to run a dataflow activity

PipeLine picture:

User's image

inside the for loop

User's image

User's image

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,627 questions
{count} votes

Accepted answer
  1. J N S S Kasyap 3,700 Reputation points Microsoft External Staff Moderator
    2025-06-18T13:17:04.4333333+00:00

    Hi @Jayanta Madhab Barman
     You're trying to get file names inside a folder using Get Metadata inside a ForEach loop in Azure Data Factory, and attempted to use the expression: 

    @activity('getMetadataForEachFolder').output.childItems[??]

    This error occurs because: 

    • The user is attempting to access an index (??) inside the childItems array, but did not provide a valid index or iterable context. 
    • In ADF, nested ForEach loops are not allowed, so you cannot directly iterate over files (childItems) inside an outer ForEach loop. 
    • Trying to simulate this by accessing an array index with childItems[??] is invalid unless you're referring to a specific number or a defined loop iterator. 

    Please follow this approach:

    1. Inside your ForEach that loops over folders, add a Get Metadata activity (getMetadataForEachFolder) to retrieve childItems (file names). 
    2. Add a Set Variable activity (array type, e.g., fileListVar) and assign: 
         @activity('getMetadataForEachFolder').output.childItems
      
      3.Pass fileListVar as a parameter to a child pipeline or a Data Flow, like: 
                 folderName = @item().name 
                 fileList = @variables('fileListVar') 
      
      4.Inside the child pipeline, use a ForEach loop over the fileList array to process files one by one.This bypasses the nested loop limitation by offloading the second loop into a separate pipeline. 

    I hope this information helps. Please do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    As your feedback is valuable and can assist others in the community facing similar issues.

    Thank you.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.