1

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.

juvchan
  • 6,113
  • 2
  • 22
  • 35
  • Have you tried that code yet? It will get so called root-level "directories" as well. – forester123 Mar 25 '16 at 06:38
  • The problem is I have to step through a collection of cloud blob items to determine which ones are cloud directories. I want to be able to build a directory tree w/o going through every blob item. – Zachary Layne Mar 31 '16 at 20:27

2 Answers2

1

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/

  • I've read about how it's a virtual directory structure. To do what I wanted, I'm thinking about writing the virtual directory as container metadata. – Zachary Layne Mar 25 '16 at 01:58
  • This is a confusing answer, possibly a wrong one as well. Maybe something changed in the API between 2016 and now, or there's something I'm missing, but there definitely are directories on Azure Blob. You can define your own folder structure and then navigate that. When listing children blobs with `.ListBlobs`, you will get a collection of `IListBlobItem` implementations, of which one is [CloudBlobDirectory](https://learn.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.blob.cloudblobdirectory?view=azure-dotnet). – Mihai Coman Nov 06 '18 at 15:52
0

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.

Mihai Coman
  • 354
  • 2
  • 6