如何使用python boto获取Amazon S3中仅文件夹的列表? [英] How can I get the list of only folders in amazon S3 using python boto?
本文介绍了如何使用python boto获取Amazon S3中仅文件夹的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用boto,python和Amazon s3.
I am using boto and python and amazon s3.
如果我使用
[列表中的键的键名(self.bucket.list())]
然后我获得了所有文件的所有密钥.
then I get all the keys of all the files.
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的答案:
building on sethwm's answer:
要获取顶层目录:
list(bucket.list("", "/"))
要获取文件的子目录
:
list(bucket.list("files/", "/")
以此类推.
这篇关于如何使用python boto获取Amazon S3中仅文件夹的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文