python - 如何使用 python boto 获取亚马逊 S3 中唯一文件夹的列表?

标签 python amazon-s3 boto

我正在使用 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/

相关文章:

python - mongodb keyerror 即使字段存在

Python PIL 图像比较问题

python - 为什么 TensorBoard Events 显示奇怪的波形图?

python - pandas groupby + 列表

android - 无法在 s3 中获取更新的对象?

amazon-web-services - 将用户名发送到由aws Cognito用户确认的aws Lambda函数

python - aws CLI 比使用 boto3 更快吗?

reactjs - 使用 HTTPS 在 AWS S3 上部署 ReactJS 应用程序

python - 将原始电子邮件(带附件)发送给多个收件人

Django - 获取 PIL 图像保存方法以与 Amazon s3boto 存储一起使用