Reputation: 4992
I want to rename an existing file in Azure Storage Explorer.
the command bar has many buttons: copy, paste, clone, delete, etc. rename is not one of them.
the context menu does not have rename either
Upvotes: 0
Views: 1421
Reputation: 10370
How to rename a blob file?
I agree with Juunas's comment you cannot rename blobs in Storage Explorer directly.
Instead, you can use the below code with package azure.storage.blob
which copies the file with the new name and deletes the old blob file using Python SDK.
In my environment, I have a blob with an image file name goodone.jpg
Portal:
Code:
from azure.storage.blob import BlobServiceClient
connection_string = "Your-storage-connection string"
container_name = "test"
file_name="goodone.jpg"
new_file_name="sample123.jpg"
client = BlobServiceClient.from_connection_string(connection_string)
container_client = client.get_container_client(container_name)
blob_client = container_client.get_blob_client(file_name)
new_blob_client=container_client.get_blob_client(new_file_name)
new_blob_client.start_copy_from_url(blob_client.url)
blob_client.delete_blob()
print("The file is Renamed successfully:",{new_file_name})
Output:
The file is Renamed successfully: {'sample123.jpg'}
Portal:
The above code executed and renamed the blob file successfully.
Upvotes: 2