-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathmove.py
More file actions
37 lines (26 loc) · 1.31 KB
/
Copy pathmove.py
File metadata and controls
37 lines (26 loc) · 1.31 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
"""
Demonstrates how to move a folder within a site.
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 cert_path, cert_thumbprint, client_id, team_site_url, tenant
def main():
argparse.ArgumentParser(description="Moves a folder within a site").parse_args()
ctx = ClientContext(team_site_url).with_client_certificate(
tenant, client_id=client_id, thumbprint=cert_thumbprint, cert_path=cert_path
)
print("Creating a temporary folders in a Documents library ...")
folder_from = ctx.web.default_document_library().root_folder.add(f"Name{uuid.uuid4().hex[:8]}")
folder_to_parent = ctx.web.default_document_library().root_folder.add(f"Name{uuid.uuid4().hex[:8]}")
# folder_to_url = "Shared Documents/archive"
print("Moving folder...")
# folder_to = folder_from.move_to_using_path(folder_to_parent).execute_query()
folder_to = folder_from.move_to(folder_to_parent).execute_query()
print("Folder has been moved into '{0}'".format(folder_to.server_relative_url))
print("Cleaning up temporary folders ...")
folder_to_parent.delete_object().execute_query()
print("Done")
if __name__ == "__main__":
main()