I am trying to rename a file in Azure File Share using the Azure python SDK. But the problem I’m facing is, it removes the file instead of renaming it.
with directory_client.get_file_client(file_name=project_from_db.project_name) as rename_client:
rename_client.rename_file(new_name=new_data['project_name'])
Is anything wrong here?
2
Answers
I solved it with the same code below, by just adding the path of the old file with the new name of the file, to the new_path parameter .
By doing the above change, the file will be renamed in the same path as the old file was.
Hope it helps other people out there facing the same issue!
I tried in my environment and got the below results:
Initially, In my environment, I have the file name with
sprite.html
in Azure File share.Portal:
You can use the below code to rename a file in Azure File Share using Azure Python SDK.
Code:
Output:
Portal:
Reference:
Azure Storage File Share client library for Python | Microsoft Learn