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读写文件模式 1、r 打开只读文件,该文件必须存在。 2、r+ 打开可读写的文件,该文件必须存在。 3、w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会...

Python 批量刷博客园访问量脚本过程解析

Python 批量刷博客园访问量脚本过程解析

今早无聊。。。7点起来突然想写个刷访问量的。。那就动手吧 仅供测试,不建议刷访问量哦~~ 很简单的思路,第一步提取代理ip,第二步模拟访问。 提取HTTP代理IP 网上很多收费的代理和...

python实现自动发送邮件

自动发送邮件功能是我们经常要用到的,比如每天定时统计报表信息,然后自动发送给运营人员,协助运营人员进行业务数据分析。本文是用Python写的一个自动发送邮件的脚本,调用函数时,直接把发件...

详解Tensorflow数据读取有三种方式(next_batch)

详解Tensorflow数据读取有三种方式(next_batch)

Tensorflow数据读取有三种方式: Preloaded data: 预加载数据 Feeding: Python产生数据,再把数据喂给后端。 Reading from...

tesserocr与pytesseract模块的使用方法解析

1.tesserocr的使用 #从文件识别图像字符 In [7]: tesserocr.file_to_text('image.png') Out[7]: 'Python3WebSp...