本文实例分析了python删除指定类型(或非指定)的文件用法。分享给大家供大家参考。具体如下:
如下,删除目录下非源码文件
import os
import string
def del_files(dir,topdown=True):
for root, dirs, files in os.walk(dir, topdown):
for name in files:
pathname = os.path.splitext(os.path.join(root, nam
删除指定后缀文件
import os
def del_files(path, delend):
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith(delend):
os.remove(os.path.join(root, name))
print("delete file :", os