10
votes

I thought that this would be very easy job to do, but as I have researched, I found nothing on how to rename a file or directory in Azure Storage.

I don't want to do a copy/delete (the size of files/directories is very large), I just want to change the name of a given file/directory programmatically through C#.

Edit: I'm talking about CloudFile/CloudFileDirectory objects.

Can someone help me?

3
Do you mean on an attached SMB3 drive? That should just be File.Move()bommelding
I'm talking about CloudFile/CloudFileDirectory. There is no Move() method.IMollov
There are no directories in cloud storage providers (AWS, S3, Openstack). Directory structures simply don't scale to cloud storage sizes. Containers/Buckets contain a flat list of files and interpret specific characters as "path separators" to emulate directoriesPanagiotis Kanavos

3 Answers

6
votes

You talk about Azure Files. Similar to Azure Blob Storage, there is no rename / move feature thus you have to copy the file (e. g. using StartCopyAsync) and then delete it using the CloudFile.DeleteAsync method.

I wrote a blog article about how to Rename Azure Storage Blob using PowerShell (same probably applies to Azure Files)

0
votes

A straightforward solution through the SDK won't work. The renaming functionality isn't supported on the REST API, so all the wrappers (Azure CLI, SDK, etc.) don't have it. The Azure Storage Explorer tool can "rename" but under the hood it clones folders/files rather than renaming (again, it's working via API)

The Wailing Wall on the Azure Feedback portal is here, please upvote:

FileShare mapping

Though, if you have some flexibility, you can mount an Azure File Share with SMB on Windows, Linux, or macOS. It does true renaming over SM. And for your app it would be just normal disk I/O operations.

-1
votes

If you want to rename an Azure blob folder manually you can download the Azure Storage Explorer tool given below, connect to your blob storage and you can rename the blob folders, you can clone the blob files also.

Azure storage explorer tool