![](/img/trans.png)
[英]How to really delete all files in a folder and the folder on Windows using python?
[英]How to delete all files in google storage folder using python
我将谷歌云存储桶路径存储在一个名为 GS_PATH 的变量中,谷歌云存储路径的示例是 gs://test/one/ 在此之下,我还有一些文件夹和文件。
如何使用 python 代码删除 gs://test/one/ 路径下的所有内容
谢谢,
阿琼
有一个 API 可以做到这一点:
from google.cloud import storage
my_storage = storage.Client()
bucket = my_storage.get_bucket('test')
blobs = bucket.list_blobs(prefix='one/')
for blob in blobs:
blob.delete()
请参阅https://cloud.google.com/storage/docs/deleting-objects#storage-delete-object-python以供参考。
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket('bucket_name')
blobs = bucket.list_blobs(prefix='folder_prefix/')
for blob in blobs:
blob.delete()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.