如何批量删除空间里的文件

最近更新时间: 2017-08-30 17:44:22

1.调用两个接口写代码循环删除

可以先调用list接口,返回如下的的json信息

然后循环调用delete接口一一删除

https://developer.qiniu.com/kodo/api/1284/list

https://developer.qiniu.com/kodo/api/1257/delete


以python为例:

# -*- coding: utf-8 -*-
from qiniu import Auth
from qiniu import BucketManager

access_key = ''
secret_key = ''

q = Auth(access_key, secret_key)
bucket = BucketManager(q)

bucket_name = ''
# 前缀
prefix = None
# 列举条目
limit = 200
# 列举出除'/'的所有文件以及以'/'为分隔的所有前缀
delimiter = None
# 标记
marker = None

ret, eof, info = bucket.list(bucket_name, prefix, marker, limit, delimiter)
for i in ret['items']:
    print(i['key'])
    ret, info = bucket.delete(bucket_name, i['key'])



2.使用qshell的batchdelete和listbucket命令

https://developer.qiniu.com/kodo/tools/1302/qshell


3.使用batch批量操作

https://developer.qiniu.com/kodo/api/1250/batch

以python为例:

# -*- coding: utf-8 -*-

from qiniu import Auth
from qiniu import BucketManager, build_batch_delete

access_key = ''
secret_key = ''

# 初始化Auth状态
q = Auth(access_key, secret_key)

# 初始化BucketManager
bucket = BucketManager(q)

keys = {'2.png':'2.png', '3.png':'3.png'}

ops = build_batch_delete('your_bucket_name', keys)

ret, info = bucket.batch(ops)
print(ret)
print(info)
以上内容是否对您有帮助?
  • Qvm free helper
    Close