我在读this tutorial,但我无法找到一种方法来列出容器下的所有(虚拟)文件夹而无需获取所有文件。我有500个(虚拟)文件夹中的26K文件。我只想获取文件夹列表,而不必等待几分钟,以获取包含整个文件列表的list_blobs
的输出。有没有办法做到这一点?或者至少告诉list_blobs
不要比容器下面的n
更深?通过python API在azure blob存储中列出虚拟文件夹
0
A
回答
1
您可以尝试类似如下:
from azure.storage import BlobService
blob_service = BlobService(account_name='account-name', account_key='account-key')
bloblistingresult = blob_service.list_blobs(container_name='container-name', delimiter='/')
for i in bloblistingresult.prefixes:
print(i.name) #this will print the names of the virtual folders
SDK Source Code Reference: BlobService.list_blobs()
SKD Source Code Reference: BlobService.list_blobs().prefixes
0
@拉夫Mantri指出了正确的方式来获得BlobPrefix元素的列表,我们可以利用它来创建一个函数来要求你的要求:
例如我有4个级别的目录:
import azure
from azure.storage.blob import BlobService
blob_service = BlobService(account_name='<account_name>', account_key='<account_key>')
def getfolders(depth=1):
result = []
searched = []
delimiter = '/'
print depth
blob_list = blob_service.list_blobs('container-name',delimiter='/')
result.extend(str(l.name) for l in blob_list.prefixes)
#for l in blob_list.prefixes:
# result.extend(str(l.name))
depth -= 1
while (depth>0):
print 'result: \n'
print ','.join(str(p) for p in result)
print 'searched: \n'
print ','.join(p for p in searched)
for p in [item for item in result if item not in searched]:
print p +' in '+ str(depth)
searched.append(p)
blob_list = blob_service.list_blobs('vsdeploy',prefix=p,delimiter='/')
result.extend(str(l.name) for l in blob_list.prefixes)
depth -= 1
return result
blob_list = getfolders(4)
print ','.join(str(p) for p in blob_list)
相关问题
- 1. 将Azure虚拟机本地文件夹备份到blob存储?
- 2. Azure Blob存储列表Blob
- 3. win32 api虚拟文件夹
- 4. 通过azure python sdk重启虚拟机
- 5. 上传存储在Azure Blob存储中的文件
- 6. 通过Azure存储获取JSON文件在HTML中通过Azure存储
- 7. Azure - 通过共享主机上传文件到blob存储
- 8. Azure Blob存储蟒蛇API性能
- 9. Azure blob存储 - 虚拟目录是否有子?
- 10. Azure blob存储;派生列
- 11. 通过Azure Logic App从azure blob存储中的目录访问文件
- 12. 无法通过Python中的azure存储包访问blob存储WebJob
- 13. 通过管理API访问azure blob存储的任何方式?
- 14. 将大文件从Azure虚拟机传输到Azure存储
- 15. FileUpload文件到Azure Blob存储
- 16. PHP在Azure:如何列出BLOB的“文件夹”
- 17. 删除Azure Blob存储容器内的文件夹
- 18. Azure blob存储文件路径限制
- 19. 将文件上传到Azure Blob存储
- 20. 与https使用Azure Blob存储REST api
- 21. 使用Azure中的命令式绑定在虚拟文件夹中搜索Azure blob功能
- 22. Azure DocumentDB和Azure Blob存储
- 23. 虚拟文件夹
- 24. Azure的Blob存储
- 25. 谷歌存储(卷曲+ PHP +创建一个虚拟_ $文件夹$)
- 26. 在Azure的Blob存储
- 27. Azure:复制虚拟机:无存储配置文件
- 28. Azure blob存储拆分blob并存储在云文件共享上
- 29. UNC虚拟文件夹
- 30. Azure Blob存储 - 在新文件上传到blob容器中的特定文件夹时设置警报