这必须很简单;如何使用fnmatch
从os.listdir
生成的打印列表中排除一个文件?你知道吗
这个python脚本只列出索引.php文件;我要排除索引.php并列出所有其他.php文件。如果我删除if fnmatch.fnmatch(entry, 'index.php'):
,我会得到所有文件的列表,包括索引.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)
相关问题 更多 >
编程相关推荐