Delete all contains with a name in blob storage
azure, azure-blob-storage, azure-storage
Solution
Maybe some regex can do the trick?
string pattern = @"/devstoreaccount1/Root/Media/([A-Za-z0-9\-]+)/cached/([A-Za-z0-9\-]+)";
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
foreach (var blob in blobClient.GetContainerReference("Root").ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true }))
{
if (Regex.Match(blob.Uri.AbsolutePath, pattern).Success)
{
((CloudBlockBlob)blob).Delete();
}
}
Of course you should first test that against some test data in the storage emulator, and note that the pattern will need to be adapted when you switch to the real cloud storage.
Hope it helps...
Problem
I'm trying to delete everything in containers named "cached" under a tree in my blob storage. My structure is something like this ``` -Root -Bin -Media -1324 -cached -5648 -cached -Images -cached ``` I want to delete everything under "media" that's in a "cached" folder. What's a good approach to this? Code by hand? I have about 100,000 folders that have the "cached" name that I would like to delete.