-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathcopy_file.py
More file actions
31 lines (23 loc) · 1.07 KB
/
Copy pathcopy_file.py
File metadata and controls
31 lines (23 loc) · 1.07 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
"""
Demonstrates how to copy a file within a site
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, password, site_url, tenant, username
def main():
parser = argparse.ArgumentParser(description="Copy a file within a site")
parser.add_argument("--file-url", default="Shared Documents/Financial Sample.xlsx", help="server-relative file URL")
parser.add_argument(
"--folder-url", default="Shared Documents/archive", help="server-relative destination folder URL"
)
args = parser.parse_args()
ctx = ClientContext(site_url).with_username_and_password(
tenant=tenant, client_id=client_id, username=username, password=password
)
file_from = ctx.web.get_file_by_server_relative_url(args.file_url)
folder_to = ctx.web.get_folder_by_server_relative_url(args.folder_url)
# folder_to = "Shared Documents/archive/2002/02"
file_to = file_from.copyto(folder_to, True).execute_query()
print(f"{file_from} copied into '{file_to}'")
if __name__ == "__main__":
main()