[英]Python: “invert” fnmatch to match one file name?
这必须很简单; 如何使用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)
import os, fnmatch
listOfFiles = os.listdir('.')
pattern = "*.php"
for entry in listOfFiles:
if entry != "index.php" and fnmatch.fnmatch(entry, pattern):
print(entry)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.