如何从Python删除GCS文件夹? [英] How to delete GCS folder from Python?

查看:58
本文介绍了如何从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 ?

我找到了这个( Google Cloud Storage :如何在stackvoerflow中使用Python(递归)删除文件夹),但是此答案只是删除文件夹中的所有文件,而不是删除文件夹本身.

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.

推荐答案

您引用的答案中提到的代码有效,前缀应如下所示:

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文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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