python删除特定文件的方法

yipeiwu_com6年前Python基础

本文实例讲述了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(".CR2"):
        os.remove(os.path.join(root, name))
        print ("Delete File: " + os.path.join(root, name))
# test
if __name__ == "__main__":
  path = '/Users/yjatt/Downloads/1104/'
  del_files(path)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Windows下Python使用Pandas模块操作Excel文件的教程

Windows下Python使用Pandas模块操作Excel文件的教程

安装Python环境 ANACONDA是一个Python的发行版本,包含了400多个Python最常用的库,其中就包括了数据分析中需要经常使用到的Numpy和Pandas等。更重要的是,...

详解如何在python中读写和存储matlab的数据文件(*.mat)

背景 在做deeplearning过程中,使用caffe的框架,一般使用matlab来处理图片(matlab处理图片相对简单,高效),用python来生成需要的lmdb文件以及做test...

初探利用Python进行图文识别(OCR)

初探利用Python进行图文识别(OCR)

话说什么是OCR????? 简介 OCR技术是光学字符识别的缩写(Optical Character Recognition),是通过扫描等光学输入方式将各种票据、报刊、书籍、文稿及其...

详解Python中的变量及其命名和打印

在程序中,变量就是一个名称,让我们更加方便记忆。 cars = 100 space_in_a_car = 4.0 drivers = 30 passengers = 90...

弄懂这56个Python使用技巧(轻松掌握Python高效开发)

1. 枚举 - enumerate 可以有参数哦 之前我们这样操作: i = 0for item in iterable: print i, item i += 1 现在我们这...