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