Copy a from a source library to a destination library a document and any folder structure it may sit inside of. The folder names will not be known

We have several SharePoint document libraries. Each one contains randomly generated folders, and inside those folders are many files.

I need to use Microsoft flow to manually copy the contents of one library to another library.

For example, the Subsite https://mysite.sharepoint.com/myprodsubsite contains a document library called account

The document library called accounts contains many folders and files, and inside each folder may exist subfolders and files.

I need to copy everything in account, including the subfolders and files, exactly as it exists in the subsite above, to the destination

https://mysite.sharepoint.com/mytestsubsite/accounts

How can I do this with Plumsail?

The examples I found seem to show doing it with a single known folder or file, and these are random and we will never know them. We just need to get EVERYTHING regardless of what is it named. And we need to preserve the folder structure and folder names.

I can do this in Flow but the microsoft component won’t copy any of the folders so thousands of documents that are in folders and subfolders end up in the root of the library, so thats why we are turning to look at Plumsail.

Another way to go about it would be to trigger a workflow on the creation or modification of a document, the workflow would need to create in the destination library, any source folders the document might sit in, within the source library, then copy the source file from the source library to the destination library so that it sits in the exact same folder in the destination.

Does anyone have an easy to understand step by step instruction on how to do this?

Hi, @CERTA-ACE.

For that purpose you can use our Action "Get SP items by CAML query". Still you'll need to copy folders and files seperately. Here's an example of how you can do it:

So, at first get all the folders from your library:

Then, copy them:
image

Do the same for files (get, the copy):
image
image

Pay attention to the CAML Query (the second query differs from the first so, that it excludes folders - " ").
Here's the query for copying:

<View>
<Query>
    <Where>
        <Eq>
            <FieldRef Name='ContentType' />
            <Value Type='Computed'>Folder</Value>
        </Eq>
    </Where>
</Query>
<ViewFields>
    <FieldRef Name="FileRef"/>
    <FieldRef Name="FileLeafRef"/>
</ViewFields>

You can find more information about it here.

As for "Another way" you described - you can just create two simple flows for copying (folder/file) to another library trigered when the file is modified or created. Here's an example:
image

Best regards, Kirill Shaklein

I am trying the “Another way” / second option that is comprised of two steps but I am getting a “BadRequest” error.

The error details are “Cannot create an item at the requested destination. Verify that the folder exists and that you have permission to edit in it.”

The PlumSail SP Account has permissions. Its the same account I used with the Microsoft Flow version that copies the documents but not the folder structure.

The error is shown as follows in the outputs section:

Inputs

Source URL

https://redactedforsecurity.sharepoint.com/sites/SITE001/SUBSITE001/SOURCELIBRARY001/TestFolder/Book.xlsx?d=w9c56f18145354ddfaf6cfff28bb718cb

Destination URL

https://redactedforsecurity.sharepoint.com/sites/SITE001/SUBSITE002/DESTINATINLIBRARY001/TestFolder/

SharePoint Site URL

https://redactedforsecurity.sharepoint.com/sites/SITE001

Outputs
Status code
400
Headers
Transfer-Encoding
chunked
Connection
keep-alive
CF-RAY
45dd9d7386a06dc6-SJC
Date
Fri, 21 Sep 2018 15:37:47 GMT
Set-Cookie
__cfduid=db5f2b3a064f1aded71bbecff684f10de1537544266; expires=Sat, 21-Sep-19 15:37:46 GMT; path=/; domain=.plumsail.com; HttpOnly
Server
cloudflare
X-Powered-By
ASP.NET
Content-Type
application/json; charset=utf-8
Content-Length
281
Body
{
“request”: {
“url”: null,
“traceId”: “0HLGV70VG3V9I83c1c845”
},
“error”: {
“code”: “ApplicationResultException”,
“message”: “Cannot create an item at the requested destination. Verify that the folder exists and that you have permission to edit in it.”,
“date”: “2018-09-21T15:37:47.1098876Z”
}
}

Hi, @CERTA-ACE.

Yes, the error occurs because there’s no destination folder existing. We’ve try to fix this problem on our side.

And we’ll get back to you. Thank you for patience

Best regards, Kirill Shaklein