1

The task here is to delete the folders inside the storage account from a Logic App. I am seeking a similar action as "Delete Blob" to delete the folders also. For example, directory structure is like

XYZ -> 2021-06-14 -> filename.json

I want to delete the folder itself but unable to find a direct action for the same. Any work arounds are also accepted.

  • Is the answer provided was helpful for you ? if so could you please accept the answer ( click on the check mark beside the answer to toggle it from greyed out to filled in.) as solution for your ask. This could be beneficial to other community members. – Madhuraj Vadde Jun 25 '21 at 11:38

2 Answers2

0

Here are some links where you have some details about deletion of files or folder inside blob using Logic App

1)https://lucavallarelli.altervista.org/blog/gdpr-logic-app-delete-blob/

2)https://sameeraman.wordpress.com/2017/08/25/logic-apps-delete-files-older-than-x-days-from-a-blob-storage/

ShrutiJoshi-MT
  • 1,622
  • 1
  • 4
  • 9
0

Azure Blob Storage does not really have the concept of folders. The hierarchy is very simple: storage account > container > blob.

I have 2 ways for this

WAY - 1 we can delete a specific Blob from the container by using delete method as follows:

public  void DeleteBlob()
{
 var _containerName = "appcontainer";
 string _storageConnection = CloudConfigurationManager.GetSetting("StorageConnectionString");
 CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(_storageConnection);
 CloudBlobClient _blobClient = cloudStorageAccount.CreateCloudBlobClient();
 CloudBlobContainer _cloudBlobContainer = _blobClient.GetContainerReference(_containerName);
 CloudBlockBlob _blockBlob = _cloudBlobContainer.GetBlockBlobReference("f115a610-a899-42c6-bd3f-74711eaef8d5-.jpg");
  
 //delete blob from container
_blockBlob.Delete();
}

Delete Action will be:

public ActionResult DeleteBlob()
{
 imageService.DeleteBlob();
 return View();
}

WAY - 2 Listing the blobs within the required container, you can then delete them individually

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("your storage account");
CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("pictures");
foreach (IListBlobItem blob in container.GetDirectoryReference("users").ListBlobs(true))
{
    if (blob.GetType() == typeof(CloudBlob) || blob.GetType().BaseType == typeof(CloudBlob))
    {
        ((CloudBlob)blob).DeleteIfExists();
    }
}

For further more analysis you can refer the following links link 1 link 2.

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18