python 删除文件夹中(含子文件夹中)特定类型文件;;;暂定删除所有非txt的文件

import os
n = 0
for root, dirs, files in os.walk('./'):
    for name in files:
        if name[-3:]  !='txt':
            n += 1
            print('正在删除第',n,'个文件,','其名为:',name)
            os.remove(os.path.join(root, name))

原文地址:https://www.cnblogs.com/Tdazheng/p/13820410.html