oss2羅列全部文件

使用oss python sdk羅列某目錄下全部文件。python

 

#!/usr/bin/python3

import sys, os
import oss2

auth = oss2.Auth('keyID', 'keySecret')
bucket = oss2.Bucket(auth, 'url', 'bucket', enable_crc=False)

is_truncated = True
next_marker = ''
while(is_truncated):
    result = bucket.list_objects(prefix="", marker=next_marker, max_keys=1000)
    is_truncated = result.is_truncated
    next_marker = result.next_marker
    oss_objects = result.object_listfor oss_object in oss_objects:
        print('find: ' + oss_object.key)
相關文章
相關標籤/搜索