【发布时间】:2013-06-26 20:12:36
【问题描述】:
我正在使用 boto、python 和 amazon s3。
如果我使用
[key.name for key in list(self.bucket.list())]
然后我得到所有文件的所有密钥。
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]
【问题讨论】:
-
我认为你的解决方案是最好的,我可以直接得到文件路径。