Skip to main content

Notifications

Community site session details

Community site session details

Session Id : YZ1FrKSylPOel+e0cAunFS
Power Automate - Building Flows
Unanswered

Copy files from SharePoint folder into SharePoint list with condition

Like (0) ShareShare
ReportReport
Posted on 2 Jun 2023 20:45:17 by 4

I have a collection of folders in SharePoint all within 1 folder. These folders have various files inside of them ranging from PDF to JPEGs. I need to move these files into a collection of lists items inside a different SharePoint folder. The transfer should occur when clicking the list item, or it should happen all at once (whatever is easiest).

 

The title of the folder must match with the transition ID of a list before a transfer can be made (i.e., contents of a folder whose title is 111 will have their files copied and pasted into the list with transition ID 111 as attachments).

 

I cannot post a screenshot of my flow attempt but I will explain it below:
Trigger: ‘For a selected item’ [list items]
‘Get items’ [from original folder]

’Filter array’ [where folder name must equal to list item transition ID]

’Apply to each’ [loop the function for each list item]

‘Create file’ [Create a copy of the files from the folder into their appropriate list item]

 

I am getting an error attempting to save, indicating that I may have invalid input parameters. How can I go about this task properly with appropriate input parameters in each action?

  • Nived_Nambiar Profile Picture
    17,554 Super User 2025 Season 1 on 13 Jun 2023 at 02:45:25
    Re: Copy files from SharePoint folder into SharePoint list with condition

    Hi @PCarti 

     

    May be give a try with this approach 

     

    Step 1: List all folders present in main folder like below

    Nived_Nambiar_0-1686623221945.png

     

    Step 2: Since List folders list all files and folder present in MainFolder, we need to get only the elements in the output json array which has folder details , so use the below filter array 

    Nived_Nambiar_1-1686623280335.png

     

    (both dynamic contents are from list folder action)

     

    Step 3: Loop through the output from Filter array using apply to each loop

    Nived_Nambiar_2-1686623354529.png

     

    Further steps below would be steps used under the loop

     

    Step 3.1: use list folder action to list all files coming under subfolder under main_folder through which we are iterating

    Nived_Nambiar_3-1686623452155.png

     

    Step 3.2: Now we need to find ID of list item to which we need to attach the attachments, for that we will be using Get items filter query 

    Nived_Nambiar_4-1686623537670.png

     

    Note: here i am using Title as identifier by which we identify required subfolder by its name and attach its contents/attachments 

    In your case if you are other columns apart from title as identifier, use appropriate column name instead of Title which i have used in Filter Query (That's all change is needed when you are designing the flow 🙂 , I think)

     

    Step 3.3: Now check whether the list item having the required title value exists for attaching attachments, use condition for that like below

    Nived_Nambiar_5-1686623902894.png

     

    length(outputs('Get_items')?['body/value'])
     
    In yes branch, we will do the following 
     
    a. Use loop to loop each files obtained as output from list folder action used in step 3.1.
    Nived_Nambiar_6-1686623998423.png

     

    In the loop 

      a1. use get attachment content to get attachment content which is currently being iterated

    Nived_Nambiar_7-1686624075668.png

     

    a2. use add attachments action to add attachment to the list item 

    Nived_Nambiar_8-1686624134723.png

     

    expression: 

    first(outputs('Get_items')?['body/value'])?['ID']
     
    Nived_Nambiar_9-1686624173965.png

     

    Nived_Nambiar_10-1686624194936.png

     

     

     

    ------------------------------------------------------------------------------------------------------------

     

    This is how flow should be designed 

     

    Output was like this

     

    In the folder, there were two files 

    Nived_Nambiar_11-1686624244340.png

     

    After running flow, files were attached to sharepoint list

    Nived_Nambiar_12-1686624316903.png

     

     

    I hope this helps you !

     

     

  • PCarti Profile Picture
    4 on 13 Jun 2023 at 01:51:17
    Re: Copy files from SharePoint folder into SharePoint list with condition

    Hi Nived,

    Thank you very much for the response. I believe that it is close to the solution; however, I seem to be receiving an error from the 'List folder' expression stating that 'The response is not in a JSON format'.
    Solutions that I have attempted but resulted in the aforementioned error:
    (1) modifying folder names to the appropriate folder as suggested by you
    (2) modifying 'Title' to 'ID' to closer match my needs

    List Folder Failure 2.jpg

    List Folder Failure.jpg


    I have also tried remove the expression and to directly link 'Test Folder'; however, the flow then had an error at 'Get file content' as it could not find the file.


    Furthermore, I'd like to clarify my goal which is to append content from one folder (which contains numerous .pdf, .jpg etc.) to a list item as attachments, but only if the folder's Title matches the list item's TransitionID. The TransitionID is a custom column but we can use a standard ID if that is easiest to demonstrate.
    Ex. 1: folder '1' content will only transfer to list item '100A' whose TransitionID is '1'
    Ex. 2: folder '5' content will only transfer to list item '200B-B' whose TransitionID is '5'
    Ex. 3: folder '6' content will only transfer to list item '#300-C/C' whose TransitionID is '6'

    Test Folder.jpg

    Test List.jpg



     

  • Nived_Nambiar Profile Picture
    17,554 Super User 2025 Season 1 on 10 Jun 2023 at 13:49:24
    Re: Copy files from SharePoint folder into SharePoint list with condition

    Hi @PCarti 

     

    Sorry for late response !

     

    Try like below 

     

    Assume you have main folder and subfolder inside it with title of list item as folder name like below

    Nived_Nambiar_3-1686404624664.png

    Nived_Nambiar_4-1686404635581.png

     

     

     

    step 1: use trigger get select item 

    step 2: use get item to get the details of that list item which is selected.

    Nived_Nambiar_1-1686404514999.png

     

     

    step 3: use list folders to list all files in the folder whose folder name is name of title of list item 

    Nived_Nambiar_2-1686404579174.png

     

    expression: 

    concat('/Shared Documents/Main_Folders/',outputs('Get_item')?['body/Title'])
     
    Here you need to replace Main_Folders with main folder name of yours where the subfolders of indiviual list items are placed.
     
    Step 4: loop through all files under the subfolder using apply to each like below
    Nived_Nambiar_5-1686404771065.png

     

    Rest steps would be steps used under the loop

     

    Step 4 a: use get file content to get file content of that file.

    Nived_Nambiar_6-1686404833544.png

     

    Step 4 b: use add attachments to add that file as attachment to list

    Nived_Nambiar_7-1686404884987.png

     

    Nived_Nambiar_8-1686404914136.png

     

    Nived_Nambiar_9-1686404942559.png

     

     

    Hope this helps !

    Mark it as solution if it resolves your query !

     

     

  • PCarti Profile Picture
    4 on 03 Jun 2023 at 20:22:49
    Re: Copy files from SharePoint folder into SharePoint list with condition

    Hey there. I am trying to copy the items in the folder to the list as attachments. However, I want the transfer filtered by folder title and list transition ID. Let me know if I can clear up anything else!

  • Nived_Nambiar Profile Picture
    17,554 Super User 2025 Season 1 on 03 Jun 2023 at 13:00:05
    Re: Copy files from SharePoint folder into SharePoint list with condition

    Hi @PCarti 

     

    Are you trying to copy it to list as attachments or to a folder ?

     

    Kindly let me know ?

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 18 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 16

#3
Churchy Profile Picture

Churchy 12

Overall leaderboard