首页 > 解决方案 > 如何从共享点上的给定文件夹中读取文件名

问题描述

我正在 python 2.7 中编写一个工具,它可以自动化我的 ETL,它将在循环中读取共享点中的文件并转换为数据帧。我的 ETL 已完成,但我无法从 sharepoint 上可以提供我的 ETL 的文件夹中读取文件名。任何帮助表示赞赏。提前致谢

我检查了 context.web 的类成员,我可以看到 get_folder_by_server_relative_url

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 
FileCreationInformation
import inspect


url= "https://XXX.sharepoint.com/sites/XXX/"
username = "blah@xxx.com.au"
password = "blah123!"

ctx_auth = AuthenticationContext(url=url)
if ctx_auth.acquire_token_for_user(username=username,password=password):
 context = ClientContext(url, ctx_auth)
 print(inspect.getmembers(context.web))

 lists = context.web.get_folder_by_server_relative_url('Shared Documents/ELZ/')
 items = lists.Folders
 context.Load(items)
 context.ExecuteQuery()


 folder = GetListItemFolder(item)
 for item in items:
   print "File name: {0}".format(item.properties["Name"])

AttributeError:“FolderCollection”对象没有属性“get_folder_by_server_relative_url”

标签: pythonrestapisharepoint

解决方案


按照下面的网址,这将对您有所帮助https://www.mydatahack.com/how-to-get-data-from-sharepoint-with-python/


推荐阅读