Skip to content

Instantly share code, notes, and snippets.

@int64ago
Created January 16, 2015 04:04
Show Gist options
  • Save int64ago/78379a6cd93a39f2d8b8 to your computer and use it in GitHub Desktop.
Save int64ago/78379a6cd93a39f2d8b8 to your computer and use it in GitHub Desktop.
Delete all zerobyte files for Qiniu
# -*- coding: utf-8 -*-
# Dependents:
# qiniu-sdk(https://github.com/qiniu/python-sdk/releases)
# requests(http://docs.python-requests.org/en/latest/user/install/)
from qiniu import Auth
from qiniu import BucketManager
access_key = '...'
secret_key = '...'
bucket_name = '...'
def del_all_zbyte_files(bucket_name, bucket, prefix=None, limit=None):
marker = None
eof = False
while eof is False:
ret, eof, info = bucket.list(bucket_name, prefix=prefix, marker=marker, limit=limit)
marker = ret.get('marker', None)
for item in ret['items']:
key = item['key']
ret, info = bucket.stat(bucket_name, key)
assert info.status_code == 200
if ret['fsize'] == 0:
ret, info = bucket.delete(bucket_name, key)
print('Del file: ' + key)
if eof is not True:
pass
q = Auth(access_key, secret_key)
bucket = BucketManager(q)
del_all_zbyte_files(bucket_name, bucket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment