<p>我正在使用boto、python和amazon s3。</p>
<p>如果我用</p>
<p><code>[key.name for key in list(self.bucket.list())]</code></p>
<p>然后我拿到所有文件的钥匙。</p>
<pre><code>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/
</code></pre>
<p>什么是最好的方法</p>
<pre><code>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
</code></pre>
<p>我想这样做</p>
<pre><code>set([re.sub("/[^/]*$","/",path) for path in mylist]
</code></pre>