Skip to content

Instantly share code, notes, and snippets.

@nuriozbey
Created September 6, 2022 11:29
Show Gist options
  • Select an option

  • Save nuriozbey/6314a0221a9646da5db233a8d5a54492 to your computer and use it in GitHub Desktop.

Select an option

Save nuriozbey/6314a0221a9646da5db233a8d5a54492 to your computer and use it in GitHub Desktop.
"""
Usage:
dir = '/teams/DataShare/Shared Documents/General/DummyFolder/'
old_name = 'dummy2_n.txt'
new_name = "dummy2.txt"
rename_file(ctx=ctx, dir=dir, old_name=old_name,new_name=new_name)
"""
def rename_file(ctx, dir, old_name, new_name):
old_url = os.path.join(dir,old_name)
source_file = ctx.web.get_file_by_server_relative_url(old_url)
new_url = os.path.join(dir,new_name)
source_file.moveto(new_relative_url=new_url, flag=1)
ctx.execute_query()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment