[英]Is it possible to list files in a dir with Azure storages
I'm using Django and django-storages[azure] as backend.我使用 Django 和 django-storages[azure] 作为后端。 But i can't to find out to list dir the files instead I have to use snippets like this:但我无法找出列出文件的目录,而是我必须使用这样的片段:
block_blob_service.list_blobs(container_name='media', prefix=folderPath)]
this is not working:这不起作用:
listdir(absoluteFolderPath)
In storages/backend/azure_storage.py I found this part:在 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
But how can I use it?但是我该如何使用它呢?
regards Christopher.问候克里斯托弗。
Assuming you have set DEFAULT_FILE_STORAGE you could access it through storage假设您已设置DEFAULT_FILE_STORAGE您可以通过存储访问它
from django.core.files.storage import default_storage
dirs = default_storage.listdir(absoluteFolderPath)
It is working thanks, but I got a list:它正在工作,谢谢,但我有一个清单:
[[], ['ANG_65096745.pdf', 'airpods-gave.png', 'miniDP_HDMI.png', 'surface-book-2-13-in-laptop-mode-device-render.jpg', 'surface_4_color.png']]
how can I use it in a for loop?如何在 for 循环中使用它? I made this:我做的:
files = default_storage.listdir(path=folderPath)
for file in files:
print(file)
but it will not print row for row just the output I wrote但它不会只打印我写的 output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.