glob
主要是用来在匹配文件,相当shell中用通配符匹配.
用法:
glob.glob(pathname) # 返回匹配的文件作为一个列表返回
glob.iglob(pathname) # 匹配到的文件名,返回一个迭代器
ps: pathname是路径, 可以是绝对和相对路径
匹配当前目录下有一个数字开头的文件
>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
匹配当前目录下所有.txt后缀的文件
>>> glob.glob('*.txt')
['172.txt', '102.txt', '185.txt', '165.txt', '11.txt', '51.txt', '91.txt', '113.txt', '78.txt', '198.txt', '35.txt', '82.txt', '171.txt', '173.txt', '97.txt', '57.txt', '37.txt', '150.txt', '42.txt', '23.txt', '25.txt', '160.txt', '143.txt', '29.txt', '149.txt', '176.txt', '191.txt', '105.txt', '86.txt', '30.txt', '120.txt', '133.txt', '68.txt', '77.txt', '41.txt', '31.txt', '152.txt', '117.txt', '175.txt', '3.txt', '159.txt', '44.txt', '19.txt', '178.txt', '200.txt', '2.txt', '112.txt', '34.txt', '17.txt', '65.txt', '183.txt', '119.txt', '18.txt', '70.txt', '40.txt', '135.txt', '89.txt', '114.txt', '184.txt', '154.txt', '61.txt', '115.txt', '94.txt', '32.txt', '92.txt', '116.txt', '5.txt', '158.txt', '157.txt', '69.txt', '137.txt', '45.txt', '111.txt', '81.txt', '15.txt', '103.txt', '10.txt', '104.txt', '95.txt', '190.txt', '145.txt', '126.txt', '96.txt', '46.txt', '122.txt', '118.txt', '84.txt', '85.txt', '195.txt', '99.txt', '79.txt', '39.txt', '64.txt', '26.txt', '197.txt', '146.txt', '163.txt', '194.txt', '179.txt', '134.txt', '7.txt', '129.txt', '189.txt', '4.txt', '170.txt', '107.txt', '155.txt', '16.txt', '109.txt', '93.txt', '121.txt', '72.txt', '56.txt', '55.txt', '67.txt', '196.txt', '177.txt', '167.txt', '192.txt', '182.txt', '80.txt', '62.txt', '186.txt', '151.txt', '169.txt', '48.txt', '147.txt', '83.txt', '74.txt', '21.txt', '124.txt', '88.txt', '142.txt', '174.txt', '139.txt', '87.txt', '128.txt', '71.txt', '53.txt', '63.txt', '156.txt', '59.txt', '1.txt', '33.txt', '108.txt', '49.txt', '75.txt', '141.txt', '136.txt', '164.txt', '131.txt', '180.txt', '38.txt', '14.txt', '28.txt', '130.txt', '22.txt', '43.txt', '168.txt', '8.txt', '144.txt', '54.txt', '12.txt', '9.txt', '187.txt', '125.txt', '166.txt', '188.txt', '199.txt', '138.txt', '181.txt', '101.txt', '27.txt', '13.txt', '36.txt', '162.txt', '153.txt', '58.txt', '50.txt', '148.txt', '47.txt', '132.txt', '140.txt', '127.txt', '90.txt', '6.txt', '100.txt', '66.txt', '193.txt', '123.txt', '98.txt', '106.txt', '52.txt', '24.txt', '76.txt', '20.txt', '60.txt', '161.txt', '73.txt', '110.txt']
glob模块相当于linux下面的通配符功能,可以用来匹配文件,不能匹配文件中的内容。
glob的更多相关文章
- node - glob模块
node的glob模块允许你使用 *等符号, 来写一个glob规则,像在shell里一样,获取匹配对应规则的文件. 这个glob工具基于javascript.它使用了 minimatch 库来进行匹配 ...
- Linux shell 通配符 / glob 模式
概念 glob 模式(globbing)也被称之为 shell 通配符,名字的起源来自于 Unix V6 中的 /etc/glob (详见 man 文档).glob 是一种特殊的模式匹配,最常见的是通 ...
- php glob()函数实现目录文件遍历与寻找与模式匹配的文件路径
采用PHP函数glob实现寻找与模式匹配的文件路径,主要讨论glob()函数的作用和用法,利用glob函数读取目录比其它的要快N倍,因为glob函数是内置函数处理起来自然要快. 一,函数原型 arra ...
- SQL入门语句之LIKE、GLOB和LIMIT
一.SQL入门语句之LIKE LIKE用来匹配通配符指定模式的文本值.如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1.这里有两个通配符与 LIKE 运算符一起使用,百 ...
- Nodejs:Glob对象
模块Glob: glob主要用处为筛选文件 API样例: var globInstance = new glob.Glob("@(a|a1|b).js",{nonull:true, ...
- glob模块
Python模块(glob) 主要是用来在匹配文件,相当于在shell中用通配符匹配. 参考: http://python.usyiyi.cn/python_278/library/glob.ht ...
- glob模式
在学习gulp的过程中,gulp使用了被称作为glob的文件匹配模式. 接下来我们认识下什么是glob模式. 在计算机编程中,特别是类Unix环境,glob模式通过通配符来匹配文件名.例如:Unix命 ...
- 实用的PHP功能详解(一)_php glob()用法
一.使用glob()查找文件 大部分PHP函数的函数名从字面上都可以理解其用途,但是当你看到 glob() 的时候,你也许并不知道这是用来做什么的,其实glob()和scandir() 一样,可以用来 ...
- 使用glob()查找文件
大部分PHP函数的函数名从字面上都可以理解其用途,但是当你看到 glob() 的时候,你也许并不知道这是用来做什么的,其实glob()和scandir() 一样,可以用来查找文件,请看下面的用法:摘自 ...
- Python标准库03 路径与文件 (os.path包, glob包)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 路径与文件的简介请参看Linux文件系统 os.path包 os.path包主要是 ...
随机推荐
- Laravel Session() 失效的问题
之前因为自己自定义了后台的路由,然后路由定义的乱七八糟的. 突然发现session失效了,记录一下,避免后者遇坑. 路由组统一通过web中间件或者存在于一个中间件中 protected $middle ...
- [Robot Framework] Robot Framework用Execute Javascript对XPath表示的元素执行Click操作
Execute Javascript document.evaluate("//a[contains(@href,'createBook')]", document, null, ...
- 使用yarn 安装 Vue-DevTools
1. 从 github 下载 vuejs/vue-devtools https://github.com/vuejs/vue-devtools/archive/dev.zip 2.安装yarn 及 编 ...
- JVM新生代到老年代基础了解
JVM区域总体分两类,heap区和非heap区. heap区又分为: - Eden Space(伊甸园). - Survivor Space(幸存者区). - Old Gen(老年代). 1个Eden ...
- oracle undo表空间
查询undo表空间状态 "Bytes(M)" FROM dba_undo_extents GROUP BY tablespace_name, status; Undo表空间的状态( ...
- 784. Letter Case Permutation
这个题的思想很重要,两种方法 第一种,回溯法 class Solution { public: int sz; vector<string> letterCasePermutation(s ...
- 2019.01.14 bzoj2648: SJY摆棋子(kd-tree)
传送门 kd−treekd-treekd−tree模板题. 题意简述:支持在平面上插入一个点,求对于一个点的最近点对. 思路:cdqcdqcdq是一种很不错的分治方法 只是好像码量有点窒息 所以我用了 ...
- 2018.12.15 hdu4641 K-string(后缀自动机)
传送门 后缀自动机基础题. 题意简述:支持动态在串尾插入字符,查询在串中出现超过kkk次的子串的个数. 动态修改samsamsam,每次增量构造好了之后在parentparentparent树上从新建 ...
- 2018.11.05 NOIP模拟 规避(最短路计数)
传送门 正难则反. 考虑计算两人相遇的方案数. 先正反跑一遍最短路计数. 然后对于一条在最短路上的边(u,v)(u,v)(u,v),如果(dis(s,u)*2<total&&di ...
- springboot 配置DRUID数据源
druid 是阿里开源的数据库连接池. 开发时整合 druid 数据源过程. 1.修改pom.xml <dependency> <groupId>mysql</gro ...