Python 循环删除指定文件夹下所有的.longtian类型文件

# -*- coding: utf-8 -*-

import os

#遍历文件夹删除文件
def traversing_dir(rootDir):
    #遍历根目录
    for root,dirs,files in os.walk(rootDir):
        for file in files:
            #文件后缀名
            extFile=os.path.splitext(file)[1]
            if extFile==".longtian":
                os.remove(os.path.join(root,file))    #删除文件
        for dir in dirs:
            #递归调用自身
            traversing_dir(dir)

if __name__=='__main__':
    path="H:\\"
    traversing_dir(path)

猜你喜欢

转载自www.cnblogs.com/zhyue93/p/python_remove.html