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')
            

    读取的文件列表

  • 相关阅读:
    JVM内存问题分析
    CAS
    普通内部类,匿名内部类和静态内部类
    文章简介
    conda更换下载源
    MySQL常见约束
    MySQL常见的数据类型
    DDL(数据定义语言)
    DML语言(数据操纵语言)
    进阶9:联合查询
  • 原文地址:https://www.cnblogs.com/reblue520/p/8405103.html
Copyright © 2011-2022 走看看