from imutils import paths 

 # 要在哪条路径下查找

 path = '...'

 # 查找图片,得到图片路径

 imagePaths = list(imutils.paths.list_images(basePath=path))

 # 所有py文件,得到py文件路径

 imagePaths = list(imutils.paths.list_files(basePath=path,,validExts=('.py')))

源码

def list_files(basePath, validExts=(".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"), contains=None):

    # loop over the directory structure

    for (rootDir, dirNames, filenames) in os.walk(basePath):

    # loop over the filenames in the current directory

        for filename in filenames:

    # if the contains string is not none and the filename does not         contain

# the supplied string, then ignore the file

if contains is not None and filename.find(contains) == -1:

continue

# determine the file extension of the current file

ext = filename[filename.rfind("."):].lower()

# check to see if the file is an image and should be processed

if ext.endswith(validExts):

# construct the path to the image and yield it

imagePath = os.path.join(rootDir, filename).replace(" ", "\\ ")

yield imagePath           

参数contains表示找到给定路径下,给定后缀文件类型,文件名中包含contains提供字段的文件

rfind() 返回字符串最后一次出现的位置(从右向左查询),如果没有匹配项则返回-1

ext = filename[filename.rfind("."):].lower() 将文件后缀转换成小写

ext.endswith(validExts) 匹配后缀,将文件路径中的空字符串" ",转化为"\\ "

imutils.path的更多相关文章

  1. NodeJs之Path

    Path模块 NodeJs提供的Path模块,使得我们可以对文件路径进行简单的操作. API var path = require('path'); var path_str = '\\Users\\ ...

  2. 【原】实时渲染中常用的几种Rendering Path

    [原]实时渲染中常用的几种Rendering Path 本文转载请注明出处 —— polobymulberry-博客园 本文为我的图形学大作业的论文部分,介绍了一些Rendering Path,比较简 ...

  3. Node.js:path、url、querystring模块

    Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...

  4. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  5. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  6. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  7. Thinking in Unity3D:渲染管线中的Rendering Path

      关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...

  8. node之path模块

    node之path模块 原文链接 //引用该模块 var path = require("path"); 1.路径解析,得到规范化的路径格式 对window系统,目录分隔为'', ...

  9. Linux系统修改PATH环境变量方法

    在Linux安装一些软件通常要添加路径环境变量PATH.PATH环境变量通俗的讲就是把程序的路径"备案"到系统中,这样执行这些程序时就不需要输入完整路径,直接在bash输入程序名就 ...

随机推荐

  1. 点击element-ui表格中的图标,上方显示具体的文字描述

    <template> <el-table :data="tableData" style="width: 100%"> <el-t ...

  2. AcWing 39. 对称的二叉树

    地址 https://www.acwing.com/problem/content/description/38/ 题目描述请实现一个函数,用来判断一棵二叉树是不是对称的. 如果一棵二叉树和它的镜像一 ...

  3. C++ 虚函数的说明

    虚函数的几点说明: 1. 当一个成员函数定义为虚函数时,其派生类中的同名函数也自动为虚函数.无论其是否添加了 virtual 关键字. 为了能良好的阅读代码,请加上. 2. 父类的虚函数,就是为了让子 ...

  4. Java四个关键字 this super final static

    一.this ​ 关键字主要有三个应用: this调用本类中的属性,也就是类中的成员变量: this调用本类中的其他方法: this调用本类中的其他构造方法初始化对象,调用时要放在构造方法的首行. 引 ...

  5. Java连载42-this不能省略的情况、构造方法设置默认值的方法

    一. this什么时候是不能省略的,我们举个例子来说明 class User2{ private int id; public int getId() { return id; } public vo ...

  6. spring cloud 2.x版本 Hystrix Dashboard断路器教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...

  7. hbase数据加盐(Salting)存储与协处理器查询数据的方法

    转自: https://blog.csdn.net/finad01/article/details/45952781 ----------------------------------------- ...

  8. 踩过了这些坑,你真的懂python基础吗?

    一.浮点数的计算 思考1:打印结果是什么? a = 0.1 b = 0.2 c = 0.3 print(b == a + a) 思考2:打印结果是什么? a = 0.1 b = 0.2 c = 0.3 ...

  9. mysql数据库的十种查询方式及多表查询

    --mysql数据库的十种查询方式 -- (1)查询时起别名 SELECT id AS '编号',NAME AS '姓名',age AS '年龄' FROM student; -- (2)查询时添加常 ...

  10. 【BZOJ1921】【CTSC2010】珠宝商(点分治,后缀自动机)

    [BZOJ1921][CTSC2010]珠宝商(点分治,后缀自动机) 题面 洛谷 BZOJ权限题 题解 如果要我们做暴力,显然可以以某个点为根节点,然后把子树\(dfs\)一遍,建出特征串的\(SAM ...