Power Automate – How to auto copy or move files in SharePoint Library

Introduction

Hi friends, let us see how we can use Power Automate (MS Flow) to automatically copy or move files from one SP document library to another whenever a file is created or modified in the source library.

Focus on the Flow

Let us see some of the simple scenarios of copying and moving the files.

Copy File

Whenever a file is uploaded to the source library, the same has to be copied to the destination library.

  • Create a flow using the trigger action named ‘When a file is created or modified in a folder‘ trigger.
  • Fill in the below properties
    • Site Address – Choose the site collection where the source library reside.
    • Folder Id – Choose the source library root folder
  • Add the action ‘Copy file‘ and fill in the below properties.
    • Current Site Address – Choose the site collection where the source library reside.
    • File to copy – Choose the ‘x-ms-file-id’ output from the trigger action
    • Destination Site Address – Choose the site collection where the destination library reside.
    • If another file is already there – This is to make sure a proper action is taken if there is a file with the same name exists on the destination library. You can choose from the actions below
      • Copy with a new name – File will be copied with the new name same as file copied to the windows explorer
      • Fail this action – No action is taken and the flow is failed.
      • Replace – The existing file will get replaced with the new file content.

Preview

Move File

Whenever a file is uploaded to the source library, the same has to be copied to the destination library.

  • Create a flow using the trigger action named ‘When a file is created or modified in a folder‘ trigger.
  • Fill in the below properties
    • Site Address – Choose the site collection where the source library reside.
    • Folder Id – Choose the source library root folder
  • Add the action ‘Move file‘ and fill in the below properties.
    • Current Site Address – Choose the site collection where the source library reside.
    • File to copy – Choose the ‘x-ms-file-id’ output from the trigger action
    • Destination Site Address – Choose the site collection where the destination library reside.
    • If another file is already there – This is to make sure a proper action is taken if there is a file with the same name exists on the destination library. You can choose from the actions below
      • Copy with a new name – File will be copied with the new name same as file copied to the windows explorer
      • Fail this action – No action is taken and the flow is failed.
      • Replace – The existing file will get replaced with the new file content.

Preview

What about Library with CheckOut feature?

The above scenario will threw issues like ‘item is in a locked mode’ because of the checkout feature enabled. The above mentioned scenarios will work only when the document is checked-in, but the documents are not gonna checkin automatically when you upload or drag the files. So the flow will fail when the document is uploaded and it will be successfull only when the file is checked-in.

Note: The trigger used in the above scenario will trigger only when the files are created or modified on the root folder of a library and not on the sub-folders inside a library.

So, how to avoid those checkin problems and how to copy or move files seamlessly without any issues? Lets see how can we overcome those issues. Inorder to overcome the above scenario, we have to change the trigger action, so lets start creating a new flow.

  • Create a flow using the trigger action named ‘When a file is created or modified (properties only)
  • Fill in the properties
    • Site Address – Choose the site collection where the source library reside.
    • Library Name – Select the source document library
    • Folder – It is an optional property. Select a specific folder when you want the flow to run only for a specific folder.
  • Add the ‘Condition‘ action and define the condition as below
triggerOutputs()?['body/{IsCheckedOut}']   is equal to    false (you have to type false in the expression and not type as a text)
  • Add the action ‘Copy file‘ or ‘Move file‘ in the Yes block of the condition action and select the ‘Identifier‘ as the value for the property ‘File to Copy‘ or ‘File to Move‘ based on the selected action.

Preview

30 thoughts on “Power Automate – How to auto copy or move files in SharePoint Library

  1. Using Power Automate for the first time. I could get the basic flow working. i.e. if i choose a particular file in a folder i can move it to the destination folder. However I want to move files (.xls) from folder to another based on file content (a particular set of cells in xl has the word – Entered or Interim) If ‘Entered’ then move to /Completed folder else move to /Interim folder. Either way also send an email. If None, then leave the file there and do nothing. Any step by step instruction to help is much appreciated. Thanks Geeta

    Like

  2. Hi Sudharsan, these look quite helpful for the first part of my requirement to identify the files based on the cell value. I will try these out for my situation and get back to you. Appreciate your help. Thanks Geeta

    Like

  3. Hi Sudharsan, tried this. However I am not able to use this since I need to specify the file name which i do not want to. I need to move all the files which have the value ‘Entered’ in cell A2 of Sheet1. Is there a way to check that without entering the file name. Geeta

    Like

  4. Oh my goodness! Incredible article dude! Thank you so much, However I am encountering troubles with your RSS. I don’t know why I can’t subscribe to it. Is there anybody getting identical RSS problems? Anyone who knows the answer will you kindly respond? Thanks!!

    Like

  5. Thanks for sharing the info with us, and I have a good method to copy from windows to SharePoint via using tools like Gs Richcopy 360 and GoodSync. I think this is the easy way

    Like

  6. I enjoyed the article, I am trying to copy the folder structure within the document library also. Either i have incorrectly set it up or the process only copies the files. Is there a way to copy the entire folder structure without making multiple flows for each folder within the document library?

    Like

  7. Hey! Thanks for the article it is very helpful. But I’m trying to do a simpler flow, just to copy SharePoint files including folder structure within sites in Power Automate, but I’m stuck. Any chance you could give me some examples?

    Thanks again

    Like

  8. Sudharsan,
    Thanks for this post! I combined your article with bits from Joanne Klein (https://joannecklein.com/2018/01/02/a-modern-transfer-to-another-location-in-office-365/) to get files based on a date filter and move these (including metadata).
    This works well for regular, smaller numbers of files. But how would you suggest to move larger numbers (say 10,000 to 100,000) once a year? Would you even use Power Automate to realize this? At our company we’re still working with the “free” version that comes with E5.

    Like

    • Hi, thanks for the feedback. Since free version comes with 2000 transactions per day, you can schedule the large numbers by breaking in to batch by batch and for different transactions you have to map different user connections. Since each user transactions are entitled to 2000 per day. The batch connot exceed 100 documents since we are not sure how the transactions count are calculated. Let me know your thoughts on this.

      Like

  9. Is it just me but the “If another file is already there” doesnt appear to work. I have a copy file step with the setting set to “Copy with a new name” but it fails that step telling me there’s a file with that name already.
    At this rate I’m going to have to create my own logic to check

    Like

  10. Hi, Is there any way to move/copy site pages along with the content? I am able to move/copy site pages but the images on that site page don’t come through. Destination site has different permissions then source site so its important to cope/move the content.

    Like

    • Hi, I haven’t tried copying or moving the pages library. Since there are lot of components involved while copying or moving the pages to another site. There can images, web parts, sections etc. Let me work on this and will try to provide the solution.

      Like

  11. Hello Sudharsan,
    I need to move existing files from one Sharepoint folder to another as a one-time exercise. The files aren’t being modified at all. Since there’s no action I’m not sure if I can set up a rule/trigger. What would you recommend?

    Like

    • Hi Matt, I apologize for the delay. There is a trigger named ‘When a file is deleted’ which will trigger the flow whenever the file or folder is deleted from a library. You can grab the file information and based on that you can delete the copy.

      Like

    • Hi, thanks for the feedback. I am not sure whether that can be tracked or not. Let me do some research and publish it if there is anything we can track the file status whether it is opened for editing or not.

      Like

  12. Pingback: Webinar: Klassisches DMS und Teams – LANSCO GmbH

Leave a comment