您的位置:首页 > 编程语言 > Python开发

python删除带特殊后缀的文件

2015-11-18 10:12 651 查看
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+"文件:"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息