0

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?

Harry
  • 55
  • 2
  • 10
  • You need to use 'GetDirectoryReference("your folder name")' and then use deleteIfExists – Llazar Nov 09 '18 at 13:57
  • what should I assign the GetDirectoryReference to? – Harry Nov 09 '18 at 13:58
  • 1
    Check this https://stackoverflow.com/questions/34727829/how-to-delete-a-folder-within-an-azure-blob-container – Llazar Nov 09 '18 at 13:59
  • @Llazar this link worked. is it possible to parse through all the folders to check in which folder this folder is present? – Harry Nov 09 '18 at 14:08
  • Programatically is posible to iterate through folders files but you need to remember that the Azure Storage doesn't have the sense of folders. – Llazar Nov 09 '18 at 14:27

1 Answers1

1

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.

Simmetric
  • 1,443
  • 2
  • 12
  • 20