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 文件夹?
基础教程推荐
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
