因此,我基本上想连接到共享点站点,查找一个名为“ archive”的特定文件夹,如果存在则不执行任何操作(这在try块内),如果该文件夹不存在,则我希望它创建它(此应该在除了块中发生) Try块工作正常,但不幸的是,我没有使用clientcontext(office365 python客户端)获得create文件夹的语法。 任何帮助都将受到赞赏。
import os
from office365.sharepoint.caml_query import CamlQuery
from office365.runtime.auth.authentication_context import
AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
from office365.sharepoint.file_creation_information import
FileCreationInformationimport
from office365.sharepoint.folder import Folder
from office365.runtime.client_query import ClientQuery
from office365.runtime.action_type import ActionType
url= "https://xxx.sharepoint.com/sites/xxx/"
username = "api.sharepoint@xxx.edu.au"
password = "xxx123!"
ctx_auth = AuthenticationContext(url=url)
if ctx_auth.acquire_token_for_user(username=username,password=password):
context = ClientContext(url, ctx_auth)
try:
#check if Archive folder exists
folder_archive =
context.web.get_folder_by_server_relative_url('Shared
Documents/ELZ/IN/Accredited/Canvas/Archive/')
context.load(folder_archive)
context.execute_query()
print("List url: {0}".format(folder_archive.properties["Name"]))
if folder_archive.properties["Name"]:
print(folder_archive.properties["Name"])
print("yass the folder exists")
except:
#folder_obj = context.web.get_folder_by_server_relative_url
folders = context.web.get_folder_by_url('Shared
Documents/ELZ/IN/Accredited/Canvas/Archive/')
folders.Add("Yay this works")
newFolder = folder_archive.add("Archive");
clientContext.ExecuteQuery();
答案 0 :(得分:0)
按照下面的URL探索在SharePoint中文件夹的创建:
https://www.example-code.com/python/sharepoint_create_folder.asp