[英]Is it possible to list files in a dir with Azure storages
我使用 Django 和 django-storages[azure] 作為后端。 但我無法找出列出文件的目錄,而是我必須使用這樣的片段:
block_blob_service.list_blobs(container_name='media', prefix=folderPath)]
這不起作用:
listdir(absoluteFolderPath)
在 storages/backend/azure_storage.py 我發現了這部分:
def listdir(self, path=''):
"""
Return directories and files for a given path.
Leave the path empty to list the root.
Order of dirs and files is undefined.
"""
files = []
dirs = set()
for name in self.list_all(path):
n = name[len(path):]
if '/' in n:
dirs.add(n.split('/', 1)[0])
else:
files.append(n)
return list(dirs), files
但是我該如何使用它呢?
問候克里斯托弗。
假設您已設置DEFAULT_FILE_STORAGE您可以通過存儲訪問它
from django.core.files.storage import default_storage
dirs = default_storage.listdir(absoluteFolderPath)
它正在工作,謝謝,但我有一個清單:
[[], ['ANG_65096745.pdf', 'airpods-gave.png', 'miniDP_HDMI.png', 'surface-book-2-13-in-laptop-mode-device-render.jpg', 'surface_4_color.png']]
如何在 for 循環中使用它? 我做的:
files = default_storage.listdir(path=folderPath)
for file in files:
print(file)
但它不會只打印我寫的 output
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.