Harry
Harry

Reputation: 55

Deleting a folder from blob container

I need to delete a folder from a blob container in Azure storage account. The folder structure is as follows:

container -> failed -> profiles

I am connecting to the container as follows:

CloudBlobClient blobClient = StorageAccountManager.getStorageAccount(ConnectionString));
var container = blobClient.GetContainerReference(container_name);

I am trying to refer to the specific folder as follows:

var blob = container.GetBlockBlobReference(failed + "/" + directory);

I also tried the follows ways:

((CloudBlob)blob).DeleteIfExists(); 
blob.DeleteIfExists();
blob.DeleteAsync();

but none of these are deleting the folder in my blob storage. Am I missing something or am I doing something wrong?

Upvotes: 0

Views: 3376

Answers (1)

Simmetric
Simmetric

Reputation: 1661

Folders in Azure Storage aren't really created or deleted, they exist as long as there are blobs stored in them. The way to delete a folder is to retrieve all blobs in it using ListBlobsSegmentedAsync and calling DeleteIfExists() on each of them.

Upvotes: 1

Related Questions