zoukankan      html  css  js  c++  java
  • 使用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()去掉换行,文件默认是
    换行,这样无法做判断
        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')
            

    读取的文件列表

  • 相关阅读:
    OCP-1Z0-053-V12.02-597题
    OCP-1Z0-053-V12.02-599题
    OCP-1Z0-053-V12.02-609题
    OCP-1Z0-053-V12.02-604题
    OCP-1Z0-053-V12.02-607题
    OCP-1Z0-053-V12.02-588题
    OCP-1Z0-053-V12.02-592题
    OCP-1Z0-053-V12.02-587题
    OCP-1Z0-053-V12.02-582题
    OCP-1Z0-053-V12.02-583题
  • 原文地址:https://www.cnblogs.com/reblue520/p/8405103.html
Copyright © 2011-2022 走看看