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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.