I'm currently trying to list specific Blobs in my storage account.
For example my container contains blob in the following structure.
https://storage.blob.core.windows.net/<containername>/<folder1>/<folder2>/<folder3>/<file>
I want to receive all the blobs that are in a location of a third folder.
So if my container had the following blobs:
- animal/herbivore/tall/giraffe.txt
- animal/herbivore/zebra.txt
- car/electric/tesla/modely.txt
- car/electric/testla.txt
I only want to list:
- animal/herbivore/tall/giraffe.txt
- car/electric/tesla/modely.txt
public async Task<List<string>> GetRecentGalleriesAsync()
{
var blobNames = new List<string>();
await foreach (BlobHierarchyItem blobItem in _containerClient.GetBlobsByHierarchyAsync(delimiter: "/", prefix: "*/*/*/"))
{
blobNames.Add($"{_containerClient.Uri.AbsoluteUri}/{blobItem.Blob.Name}");
}
return blobNames;
}
I have tried using different values for the delimiter and prefix on this method. Also, I believe the use of '*' is not allowed in the parameters. Unfortunately, I am left with an empty array. How can I only list the blobs that sits in a third folder?
I have reproduced in my environment and got expected results as below:
In portal:
Have 2 folders with structure
<folder1><folder2><folder3><file>C# code which worked for me:Output:If you want to get from 4th Folder you need to keep equal to 4( in if condition) in the code.
EDIT:
WITH LIST: