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

Everyone loves it when folks get together and share views. Great website, continue the good work!
LikeLike
Thanks for sharing the information with us.
LikeLike
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how could we communicate?
LikeLike
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
LikeLike
Hi Geeta, let me try it out and let you know the steps. But are you sure you need to check the file contents. If the files are huge and if there are lots of files then the flow will not work and its not the best practice recommended.
LikeLike
Hi Sudharsan – To give you more info – I have synced these folders – to One drive and would work on the files in One Drive. Based on this info, i need to move only those files which have the word “Entered’ in for e.g. cell A2 in Sheet 1. Unless there is a better way of doing this. Thanks appreciate your help. Geeta
LikeLike
Hi Geeta, please go through the below links and let me know whether you are able to read the data before the copy/move actions.
https://powerusers.microsoft.com/t5/Building-Flows/Excel-Read-Cell-Value-and-Send-in-Email/td-p/436306
https://anoopt.medium.com/different-ways-of-getting-excel-data-using-power-automate-e21292b1d02a
https://piyushksingh.com/2020/07/06/power-automate-read-excel-file/
LikeLike
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
LikeLike
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
LikeLike
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!!
LikeLike
Great tutorial–for anyone else struggling with the x-ms-file-id, I believe this is now Identified, not ID. 🙂
LikeLike
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
LikeLike
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?
LikeLike
Everything is very open with a clear description of the issues. It was truly informative. Your website is useful. Thanks for sharing!
LikeLike
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
LikeLike
is there a way that the column Modified of the new file on the target site, be the same value on the original site?
LikeLike
Hi, that is possible but you have to use the Http action of SharePoint and then to call ValidateUpdateListItem endpoint with the values to update the fields list Modified, Author etc.
LikeLike
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.
LikeLike
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.
LikeLike
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
LikeLike
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.
LikeLike
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.
LikeLike
Thank you Sudharsan, hope to hear from you soon.
LikeLike
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?
LikeLike