[英]Python glob matching file names?
I am trying to use the glob
module to make a list of all the Markdown files in my directory whose file paths contain either the strings abcd
or test
.我正在尝试使用
glob
模块列出我的目录中的所有 Markdown 文件,其文件路径包含字符串abcd
或test
。
I know that this is successfully printing all the files in the directory:我知道这是成功打印目录中的所有文件:
print(glob.glob('**/*.md', recursive=True))
However, I want it to only match filepaths such as /home/users/a/abcd/one.md
or /home/users/b/test/two.md
or /home/users/c/subdir/test_or_abcd/three.md
.但是,我希望它只匹配文件路径,例如
/home/users/a/abcd/one.md
或/home/users/b/test/two.md
或/home/users/c/subdir/test_or_abcd/three.md
I want it to not match filepaths like /home/users/a/other/result.md
.我希望它不匹配
/home/users/a/other/result.md
之类的文件路径。
However, when I try to do this, it doesn't work:但是,当我尝试这样做时,它不起作用:
print(glob.glob('**/*{abcd,test}.md', recursive=True))
Any suggestions or ideas on what I am doing wrong?关于我做错了什么的任何建议或想法?
Do it as many filters u have ?你有多少过滤器?
files = [
*glob.glob('**/*abcd.md', recursive=True),
*glob.glob('**/*test.md', recursive=True)
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.