0

I am using the Azure object store in the following manner:

I have one container, and beneath it many blobs in a directory structure.

I am using Azure Blob Storage api to manage it.

  • Is there a way to delete an entire directory?
  • Do I really need to list all the blobs under it and then delete them one by one?
  • Is there a workaround like deleting all blobs with the same uri prefix (again, without listing them and then deleting them one by one)?

2 Answers 2

1

I don't know if there is a new solution, but we did that using https://msdn.microsoft.com/library/microsoft.windowsazure.storage.blob.cloudblobcontainer.listblobs.aspx - if we see what is going on with Fiddler, there are only prefix-ed blobs returned. Please see if that will work for you:

static void GetBlobsByPrefix(string Container, string Prefix)
    {
        if (!string.IsNullOrEmpty(Prefix))
        {
            var _Container = GetBlobContainer(Container);
            var _Blobs = _Container.ListBlobs(Prefix, true);
            foreach (IListBlobItem blob in _Blobs)
            {

                 ....
            }
        }
    }

    static CloudBlobContainer GetBlobContainer(string container)
    {           

        CloudStorageAccount _StorageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("rus_AzureStorageConnectionString"));

        CloudBlobClient _BlobClient = _StorageAccount.CreateCloudBlobClient();
        CloudBlobContainer _Container = _BlobClient.GetContainerReference(container);
        return _Container;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, but I was looking for a solution that didn't involve listing the blobs and then going over them and delete them one by one.
0

You can delete the container and all your blobs will be deleted. Containers on Azure Storage act as a "folder" for your blobs.

1 Comment

In our current structure in the storage, there is only one container and I don't want to delete all the folders under it. before changing the structure and making each main folder a container, I wanted to be sure there is currently no way to delete all the blobs in the folder in a scalable way (or at least moving the responsibility for the efficient deletion to azure).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.