def match(value, dn, recurse):
import fnmatch
result = []
if recurse:
walk_entries = os.walk(dn)
else:
walk_entries = [(dn, [], os.listdir(dn))]
for walk_result in walk_entries:
for fn in walk_result[2]:
fn = os.path.relpath(os.path.join(walk_result[0], fn), dn)
accept = False
for token in value.split():
negate = token.startswith('-')
if negate:
token = token[1:]
if not fnmatch.fnmatch(fn, token):
continue
accept = not negate
if accept:
result.append(fn)
result.sort()
return result
评论列表
文章目录