我正在使用 boto、python 和 amazon s3。
如果我使用
[key.name for key in list(self.bucket.list())]
然后我得到所有文件的所有 key 。
mybucket/files/pdf/abc.pdf
mybucket/files/pdf/abc2.pdf
mybucket/files/pdf/abc3.pdf
mybucket/files/pdf/abc4.pdf
mybucket/files/pdf/new/
mybucket/files/pdf/new/abc.pdf
mybucket/files/pdf/2011/
什么是最好的方法
1. either get all folders from s3
2. or from that list just remove the file from the last and get the unique keys of folders
我正在考虑这样做
set([re.sub("/[^/]*$","/",path) for path in mylist]
最佳答案
以sethwm 的回答为基础:
获取顶级目录:
list(bucket.list("", "/"))
获取files
的子目录:
list(bucket.list("files/", "/")
等等。
关于python - 如何使用 python boto 获取亚马逊 S3 中唯一文件夹的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17375127/