How can we load a list of Azure blob files recursively

0 votes
Hello guys,

Azure blob files are stored in a plain list without any physical folder structure, but we can create virtual folders where each file's folder path is a part of it's name.

It brings out another problem, how to retrieve a list of ALL files in virtual sub-folder, using only that folder's name?

TIA
Aug 14, 2018 in Azure by cloudie_crank
• 1,610 points
19,531 views

1 answer to this question.

0 votes

Actually, there's a simpler way to do that and it is available in the library itself. If you look at CloudBlobContainer.ListBlobs method, it accepts two parameters:

  1. prefix: This is the name of your directory. If it is a nested directory, you will need to specify the full path e.g. myfolder/mysubfolder.
  2. useFlatBlobListing: Setting this value to true will ensure that only blobs are returned (including inside any sub folders inside that directory) and not directories and blobs.

var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
    var blobClient = account.CreateCloudBlobClient();
    var container = blobClient.GetContainerReference("blob-container-name");
    var blobs = container.ListBlobs(prefix: "container-directory", useFlatBlobListing: true);

You will get a list of all blobs belonging in the "container-directory" in blobs variable.

Hope this helps!!

To know more about Azure, enroll today with our Azure certification course.

Thanks!!

answered Aug 14, 2018 by null_void
• 3,220 points

To get to the Name property of the blob when I looped through the blobs I had to do this:

foreach (CloudBlockBlob blob in blobs)
{
     Console.WriteLine(blob.Name + " - " + blob.Uri.ToString());
}

That's ittt? Well, I'll try and let you know! Thanks.

Trying to get the size/length of the azure storage blob, file, queues& tables.

I am able to get the size of the blob by the below code but am not able to do it for others like files, queues & tables.

for (CloudBlobContainer cloudBlobContainer : cloudBlobContainers) {

                               Iterable<ListBlobItem> blobItems = cloudBlobContainer.listBlobs();

                                   for (ListBlobItem blobItem : blobItems) {
                                        if (blobItem instanceof CloudBlob) {
                                            CloudBlob blob = (CloudBlob) blobItem;
                                            size += blob.getProperties().getLength();
                                            logger.info("Size : "+blob.getProperties().getLength());
                                        }

                                    }

Hi Vyas, you can use this to get the length of blob queue:

try
{
    // Retrieve storage account from connection-string.
    CloudStorageAccount storageAccount =
       CloudStorageAccount.parse(storageConnectionString);

    // Create the queue client.
    CloudQueueClient queueClient = storageAccount.createCloudQueueClient();

    // Retrieve a reference to a queue.
    CloudQueue queue = queueClient.getQueueReference("myqueue");

   // Download the approximate message count from the server.
    queue.downloadAttributes();

    // Retrieve the newly cached approximate message count.
    long cachedMessageCount = queue.getApproximateMessageCount();

    // Display the queue length.
    System.out.println(String.format("Queue length: %d", cachedMessageCount));
}
catch (Exception e)
{
    // Output the stack trace.
    e.printStackTrace();
}

Related Questions In Azure

0 votes
1 answer

How to get the list of names of Azure blob files in a container?

We can get some additional info like Size, ...READ MORE

answered Jun 27, 2018 in Azure by club_seesharp
• 3,450 points
21,801 views
0 votes
1 answer

How to list the subscriptions of a Azure account?

Hi@akhtar, You can get all the subscriptions for ...READ MORE

answered Nov 10, 2020 in Azure by MD
• 95,460 points

edited Jul 4, 2023 by Khan Sarfaraz 1,194 views
0 votes
1 answer

How to upload a file on to Azure Blob storage without writing a code?

You can find the below tools useful ...READ MORE

answered Apr 13, 2018 in Azure by club_seesharp
• 3,450 points
1,592 views
+1 vote
1 answer

Can I rename a Azure Storage Blob?

Though the approach I'm about to share ...READ MORE

answered May 11, 2018 in Azure by club_seesharp
• 3,450 points
11,256 views
0 votes
2 answers

How can I download a .vhd image to my local machine from azure and upload the same to a different azure account?

From the Windows Azure Portal you can ...READ MORE

answered Aug 20, 2018 in Azure by Priyaj
• 58,020 points
13,985 views
0 votes
2 answers

How can I view the deployed files in Azure?

In Visual Studio, in the window "Server ...READ MORE

answered Aug 21, 2018 in Azure by Priyaj
• 58,020 points
4,940 views
0 votes
1 answer

How can i upload to Azure Blob storage with Shared Access key?

For GetBlobReferenceFromServer to work, the blob must be present ...READ MORE

answered Jun 12, 2018 in Azure by club_seesharp
• 3,450 points
3,584 views
0 votes
1 answer

Can we track progress of async file upload to azure storage?

Actually it's not possible because uploading file is ...READ MORE

answered Jun 14, 2018 in Azure by club_seesharp
• 3,450 points
5,819 views
0 votes
4 answers

How can I rename a SQL Azure database?

This command serves the purpose ALTER DATABASE [oldname] ...READ MORE

answered Nov 30, 2018 in Azure by Abhinav
2,333 views
0 votes
1 answer

How can we rewrite an URL in Azure Webapp?

You need to create a web.config file ...READ MORE

answered Jun 14, 2018 in Azure by null_void
• 3,220 points
8,710 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP