我如何使用python boto获取亚马逊S3中的唯一文件夹列表 [英] How can i get list of only folders in amazon S3 using python boto

查看:438
本文介绍了我如何使用python boto获取亚马逊S3中的唯一文件夹列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用boto,python和Amazon s3.

I am using boto and python and amazon s3.

如果我使用

[key.name for key in list(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:

要获取顶级目录,请执行以下操作:

To get the top level directories:

list(bucket.list("", "/"))

获取files的子目录:

list(bucket.list("files/", "/")

以此类推.

这篇关于我如何使用python boto获取亚马逊S3中的唯一文件夹列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆