您的位置:首页 > 其它

删除目录下的某些后缀名的文件

2014-11-17 19:29 267 查看
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import shutil

def move_logs(path,filename):
destPath = path + '/../log'
if os.path.exists(destPath):
shutil.move(os.path.join(path, filename),os.path.join(destPath, filename))

def del_files(path):
for root , dirs, files in os.walk(path):
for name in files:
if name.endswith(".exp") or name.endswith(".ilk") or name.endswith(".lib") or name.endswith(".pdb"):
os.remove(os.path.join(root, name))
elif name.endswith(".log"):
move_logs(root,name)
print ("Delete File: " + os.path.join(root, name))

# test
if __name__ == "__main__":
path = './'
del_files(path)
#move_logs(path)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: