0

Currently I have the following to list all of the blobs in my blob container:

blobs = container_client.list_blobs()

However, I am looking for a way to list all of the blobs that start with any of the letters from 'a' to 'z'. I've read about the name_starts_with parameter, but it seems I can only specify a single letter, rather than a range. For example:

blobs_with_a = container_client.list_blobs(name_starts_with='a')

Is there a way to specify a range of letters that the blob can start with rather than specifying a single character?

pkd
  • 21
  • 4
  • No, the name_starts_with is the only filter parameter available refer this https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.containerclient?view=azure-python#azure-storage-blob-containerclient-list-blobs – Mohit Ganorkar Jul 27 '22 at 19:49

1 Answers1

0

One of the workarounds is to check for the first letter of the blob making sure its ASCII value ranges from 97 to 122. Below is the code that worked for me.

import os
from azure.storage.blob import BlockBlobService

ACCOUNT_NAME = "<STORAGE_ACCOUNT_NAME>"
CONTAINER_NAME = "<CONTAINER>"
SAS_TOKEN='<SAS_TOKEN>'

blob_service = BlockBlobService(account_name=ACCOUNT_NAME,account_key=None,sas_token=SAS_TOKEN)

# Lists All Blobs
print("\nList blobs in the container")
generator = blob_service.list_blobs(CONTAINER_NAME)
for blob in generator:
    blobname=blob.name
    if(ord(blobname[0])>=97 and ord(blobname[0])<=122):
        print(blobname)

SAMPLE RESULTS:

Blobs in my storage account

enter image description here

enter image description here

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18