How to get list of folders in a given bucket using Google Cloud API(如何使用 Google Cloud API 获取给定存储桶中的文件夹列表)
问题描述
我想使用 Google Cloud Storage API 获取给定 Google Cloud 存储桶或文件夹中的所有文件夹.
I wanted to get all the folders inside a given Google Cloud bucket or folder using Google Cloud Storage API.
例如如果gs://abc/xyz包含三个文件夹gs://abc/xyz/x1,gs://abc/xyz/x2 和 gs://abc/xyz/x3.API 应返回 gs://abc/xyz 中的所有三个文件夹.
For example if gs://abc/xyz contains three folders gs://abc/xyz/x1, gs://abc/xyz/x2 and gs://abc/xyz/x3. The API should return all three folder in gs://abc/xyz.
使用 gsutil
gsutil ls gs://abc/xyz
但我需要使用 python 和 Google Cloud Storage API 来完成.
But I need to do it using python and Google Cloud Storage API.
推荐答案
您可以使用 Python GCS API 客户端库.有关指向文档和下载.
You can use the Python GCS API Client Library. See the Samples and Libraries for Google Cloud Storage documentation page for relevant links to documentation and downloads.
在您的情况下,首先我想指出您混淆了桶"一词.我建议阅读文档的 关键条款 页面.你说的是对象名前缀.
In your case, first I want to point out that you're confusing the term "bucket". I recommend reading the Key Terms page of the documentation. What you're talking about are object name prefixes.
您可以从 list-objects 开始.py 示例在 GitHub 上.查看 列表 参考页,您需要传递 bucket=abc、prefix=xyz/ 和 delimiter=/.
You can start with the list-objects.py sample on GitHub. Looking at the list reference page, you'll want to pass bucket=abc, prefix=xyz/ and delimiter=/.
这篇关于如何使用 Google Cloud API 获取给定存储桶中的文件夹列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Google Cloud API 获取给定存储桶中的文件夹列表
基础教程推荐
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
