-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathcopy_folder_using_path.py
More file actions
43 lines (31 loc) · 1.41 KB
/
Copy pathcopy_folder_using_path.py
File metadata and controls
43 lines (31 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Demonstrates how to copy a folder using a path.
See https://learn.microsoft.com/en-us/sharepoint/dev/apis/rest-api/navigation/folder-operations
"""
import argparse
import uuid
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, password, team_site_url, tenant, username
def main():
parser = argparse.ArgumentParser(description="Copies a folder to a path")
parser.add_argument("--target-url", default="Shared Documents/Archive/2001/01", help="target folder url")
args = parser.parse_args()
ctx = ClientContext(team_site_url).with_username_and_password(
tenant=tenant, client_id=client_id, username=username, password=password
)
# creates a temporary folder first in a Documents library
folder_from = ctx.web.default_document_library().root_folder.add(f"Name{uuid.uuid4().hex[:8]}")
# folder_to = ctx.web.default_document_library().root_folder.add(f"Name{uuid.uuid4().hex[:8]}")
folder_to_url = args.target_url
# copies the folder with a new name
folder = folder_from.copy_to_using_path(folder_to_url).execute_query()
print(
"Folder has been copied from '{0}' into '{1}'".format(
folder_from.server_relative_path, folder.server_relative_path
)
)
# clean up
folder_from.delete_object().execute_query()
folder.delete_object().execute_query()
if __name__ == "__main__":
main()