Copy files one by one can be painful if you’ve got a lot of them or if you need to do it regularly, there has to be a way how to automate this with Power Automate.
Let’s build a simple workflow to copy all files from one location to another on user request. That means we want to start from Instant flow using Manually trigger flow trigger.
Add New step: ‘Get files (properties only)’ and select the source of the files.
Add New step: ‘Copy file’. Select the source site, and use the ‘Identifier’ output from ‘Get files (properties only)’ as the ‘File to Copy’.
Select ‘Destination Site Address’ and for the ‘Destination folder’ fields. Instead of using dynamic content in the field click on the folder icon on the right side to display selection of all available libraries on the destination site. Also select what should happen it file already exists on the destination site.
Now you can find it under My flows and run it by pressing the Play button.
If your document library contains also folder structure, you might need to add one more condition into the Power Automate flow to copy the folders together with the files, and even keep them synchronised in the future.
You can also copy files between multiple libraries in a single flow with a simple configuration list, or copy the created and modified information.
This is great except it copied all the files and nested folders from one site and placed them all in the root folder of the destination. Is it possible to maintain the folder structure during the copy?
Hello Angus,
I think you’ll need to go folder by folder, ‘Get files’ from one folder, ‘Copy file’ to the same folder on the other site. And repeat that for all the folders.
Hello Angus,
I played with the flow a bit and found a solution for the folder structure: https://tomriha.com/how-to-copy-sharepoint-files-including-folder-structure-in-power-automate/
Hey guys.
My work team changes the file title with the current date at the end.
How do I copy the file that changes the title every time?
Hello Lucas,
I believe the solution would be the same, if you build a flow to take all the files and copy them to another location then the file name doesn’t matter, it’ll create a file with the same name, with the date at the end, in the target location.
Great article Tom! I was looking for a long time for a way to copy SharePoint files (or actually SharePoint pages from the Site pages library) with Flow. This works great (for the library name, just enter the library GUID) 🙂
Thanks for sharing. I have a question, is there a way to retain the date created and modified dates from the original library?
Hello UB,
I would recommend to create a separate SharePoint columns for the information as described in the latest post: https://tomriha.com/copy-files-including-created-and-modified-date-with-power-automate/.
Hi,
Is there a way to trigger the copying when there is any change in the source folder ?
thanks
Hello Harsh,
yes, it is. I wrote a blog post about such flow here: https://tomriha.com/synchronise-sharepoint-libraries-with-folder-structure-in-power-automate/, all you have to add is to select a specific folder in the trigger.
I keep getting a URL not valid error in the target tenant. I gave bi-lateral permissions to each tenant as well and nothing. is there another step in in there that I am missing?
Hello Leonardo,
Power Automate flows work only in a single tenant, you can’t use it to copy files between multiple tenants.
Thanks, Tom for the excellent articles – I’m just getting started, and your posts are helping me quite a bit.
I think there have been some changes since you originally wrote this article, so here’s what I’ve learned from working on this. My use case is to copy a multi-level folder structure (with files) from one SharePoint Library to one in a different SharePoint site.
First, in your ‘Get Files (properties only)’ step, if you choose ‘Include Nested Items’ = No, then you’ll only get the top level folder (both files and folders), and no longer any need to write the condition statement that you show in your article: https://tomriha.com/how-to-copy-sharepoint-files-including-folder-structure-in-power-automate/
Second, using ‘Copy file’ on all items, I was getting a ‘File Not Found’ error on the folders. It still worked (copied all files and folders including subfolders), but just reported that it failed every time.
The solution was to add a condition inside the ‘Apply to each’ loop: IsFolder is equal to true, and use Copy folder if true, else Copy file.
This works great with no errors, copying the full tree.
Thanks again for your great content. Keep it coming!
Hello kurt,
thank you for sharing your solution, I totally forgot about the possibility to not include the nested items, that simplifies the solution a lot.
Hello I had used the same steps to get the work done but my flow is getting failed with the error stating ” response not in json format” but the files are getting moved can anyone help, thanks in advance.
Hello Pruthvi,
I’ve seen the error already a few times and I have no idea how to handle it, it says that SharePoint sent back an unexpected response, but it copies the file anyway. I’d probably ignore it if you’re using the flow for a one-time copy.
Hi Tom,
I have followed the steps, but in my case i want to copy the Pages from Site Pages of one sharepoint site to another sharepoint site. I tried but i am getting an error that states ‘the query cannot be completed because the number of look up columns it contains exceed the lookup column threshold’. I tried to increase the threshold but in the library setting of site pages i wasn’t able to get the pagination option, however, the threshold and pagination option does appear in Document library settings. Would be great if you can help me out. Look forward to your email.
Hello Mridul,
Google returned this article: https://www.c-sharpcorner.com/article/msflow-lookup-columns-exceed-the-threshold-enforced-by-adminstrator/
This works great, however, it stops at 100 files. It won’t go beyond that.
Hello Jennifer,
it’s because the ‘Get items’ and ‘Get files’ actions have a limit of 100 items (https://tomriha.com/how-to-get-over-100-items-limit-with-the-get-items-in-power-automate/). Even though the ‘Top Count’ says ‘Default = all’ in reality it’s ‘Default = 100’. Just put a higher number in there.
Hello, is it possible to copy the files with their associated metadata? And not just the file itself..
Hello Edgar,
if the metadata is not included then you can use ‘Update file properties’ to compy the metadata.
Hello Tom, Edgar,
I’m using “Update file properties” to update metadata after the copy file, it works great but the issue is it generates 2 file versions in history…Since we are using this process for DMS (safe source of important documents), it causes issues in audits we have on file generation…I could not get around it.
If I’m using SP.MoveCopyUtil.CopyFileByPath() in a REST API call, file get copied but history is deleted.
If I’m using CreateCopyJobs in a REST API call, file gets copied but it’s also copying source version history….
I don’t know if you came around this? Thanks
Hello Mike,
you could try to update the properties using an HTTP request as described here: https://tomriha.com/update-sharepoint-column-without-new-item-version-in-power-automate/
Hi,
I may have missed the comments. My flow works and it does copy files from one sharepoint folder to the other. All the files will keep their names.
However, in the the destination, all the version history disappears. Is there a way to retain it?
Hello Cheryl,
you can’t copy the old version history of the original file, it takes only the currently available version. But it’s possible to update the destination file instead of replacing it during the copy action as explained here: https://tomriha.com/how-to-update-not-replace-an-existing-file-in-power-automate/
Hi Tom, I’m trying to copy files with specific column information from one SharePoint library to another, but nothing I’ve tried so far works. Do you have a solution for getting power automate to only copy the files that have specific column data?
Hello Schezelle,
take a look on the filtering articles, you can filter only the desired files before you copy them: https://tomriha.com/category/filters/
Is there a way to do this with selected files. I only want to copy the selected files from one library to another library.
Hello Mike,
yes, you can filter the files to copy using filter in the ‘Get files…’ action: https://tomriha.com/category/filters/
Hello.
Do you know how to copy the Document Library body of a SharePoint to another SharePoint?
The contents do not need to be copied.
Hello yuki,
I believe that document libraries can’t be copied, you’ll have to recreate the whole library, either manually or with a script/flow, adding the columns one by one.
Hello There,
Could you please help me with how to exclude a specific folder (with files) to be copied?
example:
General > Main Folder
Folder 1 > Sub folder
Folder 2 > Sub folder >> I want this entire folder not to be copied in my power automate flow.
Thank you in advance.