这必须很简单;如何使用
fnmatch
从由生成的打印列表
os.listdir
?
这个python脚本只列出index.php文件;我想排除index.php并列出所有其他.php文件。如果我移除
if fnmatch.fnmatch(entry, 'index.php'):
我得到所有文件的列表,包括index.php。是否可以“反转”
Fnmatch公司
?
import os, fnmatch
listOfFiles = os.listdir('.')
pattern = "*.php"
for entry in listOfFiles:
if fnmatch.fnmatch(entry, 'index.php'):
if fnmatch.fnmatch(entry, pattern):
print (entry)