Zachary Layne
Zachary Layne

Reputation: 21

.NET Azure Blob Storage: Get Root-Level Directories w/o Listing All Blobs

I have an Azure cloud blob storage account & I need to enumerate its contents. The account has a large amount of data & using ListBlobs to enumerate all its contents takes a long time to complete.

For both cloud containers & directories, I want the ability to enumerate only root-level items. For a container, I assume this will enumerate root-level blobs:

cloudBlobContainer.ListBlobs(
            String.Empty,
            false,
            BlobListingDetails.None,
            null,
            null))

Is there any reasonable way to get root-level directories without listing all blobs? The only way I can think to do it is absurd: make calls to ListBlob with every possible combination a blob prefix could be.

Upvotes: 1

Views: 2683

Answers (2)

Mihai Coman
Mihai Coman

Reputation: 354

You can achieve a more granular listing of a directory's contents by using the .ListBlobs().OfType<your_chosen_blob_type>() call. One blob type is CloudBlobDirectory, for example. See this answer: https://stackoverflow.com/a/14440507/9654964.

Upvotes: 0

user189198
user189198

Reputation:

Zachary, unfortunately there is no such thing as a "directory" in Azure Blob Storage. The object hierarchy is as follows:

  • Storage Account (Management Plane)
    • Storage Container [0..n] (Data Plane)
      • Blobs [0..n] (Data Plane)

When you see additional forward slashes in the blob names, it is only a "virtual" directory, not a separate directory entity.

https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/

Upvotes: 1

Related Questions