简体   繁体   English

如何在 Azure Python SDK 中列出从“a”到“z”的 blob 名称?

[英]How to list blob names from 'a' to 'z' in Azure Python SDK?

Currently I have the following to list all of the blobs in my blob container:目前我有以下列出我的 blob 容器中的所有 blob:

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'.但是,我正在寻找一种方法来列出以“a”到“z”中的任何字母开头的所有 blob。 I've read about the name_starts_with parameter, but it seems I can only specify a single letter, rather than a range.我已经阅读了有关 name_starts_with 参数的信息,但似乎我只能指定一个字母,而不是一个范围。 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?有没有办法指定blob可以开始的字母范围而不是指定单个字符?

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.一种解决方法是检查 blob 的第一个字母,确保其 ASCII 值范围从 97 到 122。下面是对我有用的代码。

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我的存储帐户中的 Blob

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过Python Azure SDK知道Azure Blob对象的大小 - How to know the size of an Azure blob object via Python Azure SDK Python Azure SDK上载Blob - Python Azure SDK Uploading a Blob 如何增加 blob_client.download_blob() 的 ResponseBodySize (Azure Blob Storage Python SDK) - How to increase the ResponseBodySize of blob_client.download_blob() (Azure Blob Storage Python SDK) 如何使用多线程搜索blob? - Azure Python SDK - How to use multithreading to search for blob? - Azure Python SDK Python Azure SDK 如何获得以前版本的 blob - Python Azure SDK how to get a previous version of a blob Azure Blob 存储 Python SDK MAC 签名 - Azure Blob Storage Python SDK MAC signature Azure SDK for Python 批量读取blob数据 - Azure SDK for Python read blob data in batches Azure Python SDK - 向 Blob 存储进行身份验证 - Azure Python SDK - authenticate to Blob Storage 使用适用于 Python 的 Azure 存储 SDK 将多个文件从文件夹上传到 Azure Blob 存储 - Upload multiple files from folder to Azure Blob storage using Azure Storage SDK for Python 如何使用 Python 从给定 SAS URI 和容器名称的 Azure Blob 存储下载文件列表? - How to download a list of files from Azure Blob Storage given SAS URI and container name using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM