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?

5
  • You need to use 'GetDirectoryReference("your folder name")' and then use deleteIfExists Commented Nov 9, 2018 at 13:57
  • what should I assign the GetDirectoryReference to? Commented Nov 9, 2018 at 13:58
  • 1
    Check this stackoverflow.com/questions/34727829/… Commented Nov 9, 2018 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? Commented Nov 9, 2018 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. Commented Nov 9, 2018 at 14:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.