使用python脚本批量删除阿里云oss中的mp4文件
#encoding:utf-8
'''
oss中有一些mp4文件需要删除,首先定位出这些文件放在txt文本中
然后通过python操作oss进行批量删除
'''
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')
读取的文件列表