python 模組fnmatch

種花童心發表於2021-01-01

fnmatch 模組下的 fnmatch() 函式要求兩個引數:檔名,以及檔名模式,返回的是布林值。檔名模式中,支援 * 符號匹配任意字元。結合列表生成式,我們就可以快速過濾出符合條件的檔名了。

from fnmatch import fnmatch
path='...'
files = os.listdir(path)
deps = [i for i in files if fnmatch(i, "*共同內容.xlsx")]
print(deps)

相關文章