首页 > 其他 > 详细

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

时间:2014-11-17 20:55:33      阅读:258      评论:0      收藏:0      [点我收藏+]
#!/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)

 

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

原文:http://www.cnblogs.com/sdu20112013/p/3979781.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!