python删除带特殊后缀的文件

来源:互联网 发布:网易邮箱端口号 编辑:程序博客网 时间:2024/05/19 02:45
import os
import time
path = "F:\\zjbg" #文件夹路径
suffix = ".html" #需要删除的文件类型
def GetFileList(dir, fileList): 
    newDir = dir 
    if os.path.isfile(dir):
        if dir.endswith(suffix) :
             fileList.append(dir)
             os.remove(dir)
             print "删除文件名:" + dir
    elif os.path.isdir(dir):   
        for s in os.listdir(dir): 
            newDir=os.path.join(dir,s) 
            GetFileList(newDir, fileList)   
    return fileList 
list = GetFileList(path, [])
print "已删除当前所有"+suffix+"文件:"
0 0
原创粉丝点击