您的位置:首页 > 编程语言 > Python开发

Python_API_File and Directory Access_glob.glob

2012-03-28 22:29 399 查看
API文档:

glob

The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell. No tilde expansion is done, but*,?,
and character ranges expressed with[] will be correctly
4000
matched. This is done by using theos.listdir()
andfnmatch.fnmatch() functions in concert, and not by actually invoking a subshell.

翻译文档:

用于匹配目录路径,返回一个list。这个函数实际调用的是os.listdir()和fnatch.fnmatch()两个函数来执行。不是通过shell来执行匹配

例子:

import glob

pathStr = 'F:\\pyWorkSpace\\notes\\dPython\\music\\_singles\\'

print glob.glob(pathStr+'*.mp3')

print glob.glob(pathStr+'a*.mp3')

输出:

['F:\\pyWorkSpace\\notes\\dPython\\music\\_singles\\aa.mp3']

['F:\\pyWorkSpace\\notes\\dPython\\music\\_singles\\aa.mp3']
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息