问题描述
我有一个包含一堆文件的目录:eee2314
,asd3442
...和eph
.
I have a directory with a bunch of files inside: eee2314
, asd3442
... and eph
.
我想使用glob
函数排除所有以eph
开头的文件.
I want to exclude all files that start with eph
with the glob
function.
我该怎么办?
推荐答案
glob的模式规则不是正则表达式.相反,它们遵循标准的Unix路径扩展规则.只有几个特殊字符:两个不同的通配符,并且支持字符范围[来自 glob ].
The pattern rules for glob are not regular expressions. Instead, they follow standard Unix path expansion rules. There are only a few special characters: two different wild-cards, and character ranges are supported [from glob].
因此您可以排除某些带有模式的文件.
例如,要使用glob排除清单文件(以_
开头的文件),可以使用:
So you can exclude some files with patterns.
For example to exclude manifests files (files starting with _
) with glob, you can use:
files = glob.glob('files_path/[!_]*')
这篇关于全局排除模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!