快速删除指定目录的指定条件的文件

 

 

import os, glob

d = glob.glob(os.path.dirname(os.path.abspath(__file__)))

os_sep = os.sep
this_file_abspath= os.path.dirname(os.path.abspath(__file__))
r = []
for root, dirs, files in os.walk(this_file_abspath, True):
    # print(root)  # 主目录
    for item in files:  # 主目录下的文件夹
        # print(os.path.join(root, item))
        r.append(os.path.join(root, item))

rm_s_l = ['.mp3', '.avi', 'BANNER', '.mp4', 'mylogo']
for i in r:
    for ii in rm_s_l:
        if ii.upper() in i.upper():
            print(i)
            try:
                os.remove(i)
            except Exception as e:
                print(e)

  

 

posted @ 2018-05-15 21:27  papering  阅读(184)  评论(0编辑  收藏  举报