How to copy folder and its content into new location in SharePoint Online with python office365 module

454 views Asked by At

I am trying to copy a folder with all its content from one site to another in SharePoint Online. So I created a code that recursively creates the folder structure.
What I can't do is to copy the files. For the start I am trying to test the following very simple code which I got from GitHub

url = 'https://company.sharepoint.com/sites/MyTeam'
ctx = ClientContext(url).with_credentials(ClientCredential(client_id, client_secret))

source_folder = ctx.web.get_folder_by_server_relative_url('Shared Documents/from')    
target_folder = source_folder.copy_to('Shared Documents/to').get().execute_query()
    

This code doesn't do anything at all.
I tried to check the paths and print out the files in the source_folder and target_folder. It prints out the files in the source_folder and prints nothing for the target_folder.
What am I missing here?

1

There are 1 answers

1
Michael Han On

You could try to use sever relatice url like this:

/sites/MyTeam/Shared Documents/from and /sites/MyTeam/Shared Documents/to

Check if it works.