How to delete GCS folder from Python?(如何从 Python 中删除 GCS 文件夹?)
问题描述
使用 https://github.com/googleapis/google-cloud-python/tree/master/storage 或 https://github.com/GoogleCloudPlatform/appengine-gcs-client,我可以通过指定文件名来删除文件,但似乎没有删除文件夹的方法.
Using https://github.com/googleapis/google-cloud-python/tree/master/storage or https://github.com/GoogleCloudPlatform/appengine-gcs-client, I can delete a files by specifying its file name, but there seems not to be ways to delete folders.
有什么方法可以删除文件夹吗?
Is there any ways to delete folders ?
我找到了这个(谷歌云存储: How to Delete a folder (recursive) in Python) in stackvoerflow,但这个答案只是删除文件夹中的所有文件,而不是删除文件夹本身.
I found this(Google Cloud Storage: How to Delete a folder (recursively) in Python) in stackvoerflow, but this answer simply deletes all the files in the folder, not deleting the folder itself.
推荐答案
你提到的anwser中提到的代码工作,前缀应该是这样的:
The code mentioned in the anwser you referred works, the prefix should look like this:
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket('my-bucket')
blobs = bucket.list_blobs(prefix='my-folder/')
for blob in blobs:
blob.delete()
这篇关于如何从 Python 中删除 GCS 文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Python 中删除 GCS 文件夹?


基础教程推荐
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01