ARTICLE AD BOX
Use a flat listing, contrary to what you are experiencing, shows a sample output for GetBlobsAsync() without the folder:
The sample output is similar to:
Blob name: FolderA/blob1.txt Blob name: FolderA/blob2.txt Blob name: FolderA/blob3.txt Blob name: FolderA/FolderB/blob1.txt Blob name: FolderA/FolderB/blob2.txt Blob name: FolderA/FolderB/blob3.txt Blob name: FolderA/FolderB/FolderC/blob1.txt Blob name: FolderA/FolderB/FolderC/blob2.txt Blob name: FolderA/FolderB/FolderC/blob3.txtHowever, that's followed up by a note that explains a situation similar to yours, emphasis mine:
Note
The sample output shown assumes that you have a storage account with a flat namespace. If you've enabled the hierarchical namespace feature for your storage account, directories are not virtual. Instead, they are concrete, independent objects. As a result, directories appear in the list as zero-length blobs.For an alternative listing option when working with a hierarchical namespace, see List directory contents (Azure Data Lake Storage).
A naive solution could be to check the length. I assume this refers to BlobItem.Properties.ContentLength. But you might have non-directory blobs that are also zero-length, which would make this criteria ambiguous.
Given that you are thinking in terms of a hierarchy and have apparently organized your blobs this way, it would be a better idea to express this intent explicitly and Use a hierarchical listing which provides you with BlobHierarchyItem.IsPrefix, the property you are asking for:
Use a hierarchical listing
When you call a listing operation hierarchically, Azure Storage returns the virtual directories and blobs at the first level of the hierarchy.
To list blobs hierarchically, call the BlobContainerClient.GetBlobsByHierarchy, or the BlobContainerClient.GetBlobsByHierarchyAsync method.
The following example lists the blobs in the specified container using a hierarchical listing, with an optional segment size specified, and writes the blob name to the console window.
private static async Task ListBlobsHierarchicalListing(BlobContainerClient container, string prefix, int? segmentSize) { try { // Call the listing operation and return pages of the specified size. var resultSegment = container.GetBlobsByHierarchyAsync(prefix:prefix, delimiter:"/") .AsPages(default, segmentSize); // Enumerate the blobs returned for each page. await foreach (Page<BlobHierarchyItem> blobPage in resultSegment) { // A hierarchical listing may return both virtual directories and blobs. foreach (BlobHierarchyItem blobhierarchyItem in blobPage.Values) { if (blobhierarchyItem.IsPrefix) { // Write out the prefix of the virtual directory. Console.WriteLine("Virtual directory prefix: {0}", blobhierarchyItem.Prefix); // Call recursively with the prefix to traverse the virtual directory. await ListBlobsHierarchicalListing(container, blobhierarchyItem.Prefix, null); } else { // Write out the name of the blob. Console.WriteLine("Blob name: {0}", blobhierarchyItem.Blob.Name); } } Console.WriteLine(); } } catch (RequestFailedException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }The sample output is similar to:
Virtual directory prefix: FolderA/ Blob name: FolderA/blob1.txt Blob name: FolderA/blob2.txt Blob name: FolderA/blob3.txt Virtual directory prefix: FolderA/FolderB/ Blob name: FolderA/FolderB/blob1.txt Blob name: FolderA/FolderB/blob2.txt Blob name: FolderA/FolderB/blob3.txt Virtual directory prefix: FolderA/FolderB/FolderC/ Blob name: FolderA/FolderB/FolderC/blob1.txt Blob name: FolderA/FolderB/FolderC/blob2.txt Blob name: FolderA/FolderB/FolderC/blob3.txtNote
Blob snapshots cannot be listed in a hierarchical listing operation.
