简体   繁体   English

使用 Python 在 sharepoint 中将文件从一个文件夹移动到另一个文件夹

[英]Move file from one folder to another in sharepoint using Python

I am trying to move the file from one folder to another in SharePoint using library office365.我正在尝试使用库 office365 将文件从 SharePoint 中的一个文件夹移动到另一个文件夹。

below is the code that I have written -下面是我写的代码 -

from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.client_request_exception import ClientRequestException
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.files.file import File

ctx_auth = AuthenticationContext(url_shrpt)
if ctx_auth.acquire_token_for_user(username_shrpt,password_shrpt):
  ctx = ClientContext(url_shrpt, ctx_auth)
  file = ctx.web.get_file_by_server_relative_url(old_url)
  ctx.load(file)
  ctx.execute_query()
  File.moveto(ctx, new_relative_url=new_url, flag=1)

I am getting the error -我收到错误消息-

"'ClientContext' object has no attribute 'context'"
AttributeError                            Traceback (most recent call last)
<command-527297> in <module>
      6   ctx.load(file)
      7   ctx.execute_query()
----> 8   File.copyto(ctx, new_relative_url=new_url, overwrite=True)

/databricks/python/lib/python3.8/site-packages/office365/sharepoint/files/file.py in copyto(self, new_relative_url, overwrite)
    124         :type overwrite: bool
    125         """
--> 126         qry = ServiceOperationQuery(self,
    127                                     "CopyTo",
    128                                     {

/databricks/python/lib/python3.8/site-packages/office365/runtime/queries/service_operation_query.py in __init__(self, binding_type, method_name, method_params, parameter_type, parameter_name, return_type, is_static)
     16         :type method_name: str or None
     17         """
---> 18         super(ServiceOperationQuery, self).__init__(binding_type.context,
     19                                                     binding_type,
     20                                                     parameter_type,

AttributeError: 'ClientContext' object has no attribute 'context'

Can anyone help me with this error谁能帮我解决这个错误

Maybe you can try this:也许你可以试试这个:

from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.client_request_exception import ClientRequestException
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.files.file import File

ctx_auth = AuthenticationContext(url_shrpt)
if ctx_auth.acquire_token_for_user(username_shrpt,password_shrpt):
  ctx = ClientContext(url_shrpt, ctx_auth)
  source_file = ctx.web.get_file_by_server_relative_url(old_url)
  source_file.moveto(new_relative_url=new_url, flag=1)
  ctx.execute_query()

Thanks.谢谢。

Reference: https://github.com/vgrem/Office365-REST-Python-Client/issues/157参考: https://github.com/vgrem/Office365-REST-Python-Client/issues/157

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用python将文件从一个文件夹移动到另一个文件夹相同的ftp - How to move file from one folder to another folder same ftp using python Google Cloud Storage - 将文件从一个文件夹移动到另一个文件夹 - 使用 Python - Google Cloud Storage - Move file from one folder to another - By using Python Python - 将文件从一个文件夹移动到另一个文件夹 - Python - move files from one folder to another 如何将文件从一个文件夹从python移动到另一个文件夹 - How to move Files from one folder to another folder from python 有没有办法使用 Boto3 python 在 S3 中将具有特定文件扩展名的所有文件从一个文件夹移动到另一个文件夹? - Is there a way to move all files with specific file extensions from one folder to another in S3 using Boto3 python? 使用特定位置python将文本从一个文件移动到另一个文件 - Move text from one file to another using specific positions python Python - 将行从一个文件移动到另一个文件 - Python - Move line from one file to another 如何在python中将文本文件中列出的文件从一个文件夹移动到另一个文件夹 - How to move files listed in a text file from one folder to another in python Python - 如果文件名包含指定的单词,则将所有文件从一个文件夹移动到另一个文件夹 - Python - move all files from one folder to another if their file names contain specified words Python 忽略大小写将图片从一个文件夹移动到另一个文件夹 - Python move pictures from one folder to another ignoring case
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM