#encoding:utf-8
'''
oss中有一些mp4文件須要刪除,首先定位出這些文件放在txt文本中
而後經過python操做oss進行批量刪除
'''python
import oss2 auth = oss2.Auth('key01', 'key02') # Bucket處於新加坡區域 endpoint = 'http://oss-cn-beijing.aliyuncs.com' bucket1 = 'ck' # service = oss2.Service(auth, endpoint, ) bucket = oss2.Bucket(auth, endpoint, bucket1) f_handle = open('ck.txt','r') # 循環找出mp4文件 while True: # 注意必定要strip()去掉換行,文件默認是\n換行,這樣沒法作判斷 video_file = f_handle.readline().strip() # print type(video_file) # 文件結束後跳出循環 if video_file == '': break # 判斷是不是mp4文件 if video_file.endswith('.mp4'): exist = bucket.object_exists(video_file) if exist: print('%s object exist' % video_file) bucket.delete_object(video_file) else: print('object not eixst')
讀取的文件列表ide