How to rename a blob file in Azure Storage Explorer?

453 views Asked by At

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.

enter image description here

the context menu does not have rename either enter image description here

1

There are 1 answers

0
Venkatesan On

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: enter image description here

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'} 

enter image description here

Portal:

The above code executed and renamed the blob file successfully.

enter image description here