python遍历文件夹并删除特定格式文件的示例

yipeiwu_com6年前Python基础

复制代码 代码如下:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os

def del_files(path):
    for root , dirs, files in os.walk(path):
        for name in files:
            if name.endswith(".tmp"):
                os.remove(os.path.join(root, name))
  print ("Delete File: " + os.path.join(root, name))

# test
if __name__ == "__main__":
    path = '/tmp'
    del_files(path)

相关文章

Python动态生成多维数组的方法示例

Python动态生成多维数组的方法示例

本文实例讲述了Python动态生成多维数组的方法。分享给大家供大家参考,具体如下: 多维数组其实就是多个一维数组的嵌套,Python中有原生的list,类似一个动态数组。 所以动态生成...

python给指定csv表格中的联系人群发邮件(带附件的邮件)

以下为使用python给指定路径的csv表格中的联系人群发带附件的邮件(csv表格的第一列为联系人姓名,第二列为联系人邮箱账号)的代码,详情见注释。 import time impo...

pytorch索引查找 index_select的例子

index_select anchor_w = self.FloatTensor(self.scaled_anchors).index_select(1, self.LongTensor...

浅谈Python处理PDF的方法

浅谈Python处理PDF的方法

处理pdf文档 第一、 从文本中提取文本 第二、 创建PDF 两种方法 #使用PdfFileWriter import PyPDF2 pdfFiles = [] for fi...

python的pygal模块绘制反正切函数图像方法

python的pygal模块绘制反正切函数图像方法

python是一个很有趣的语言,可以在命令行窗口运行。python中有很多功能强大的模块,这篇经验告诉你,如何使用python的pygal模块绘制反正切函数图像。 1.简介 pygal是...