def rcollect(path, depth, filter=None):
filter = filter or (lambda n: not n.startswith('.'))
path = os.path.expanduser(path)
if os.path.exists(path):
for f in os.scandir(path):
if filter(f.name):
t = 'undefined'
try:
t = 'file' if f.is_file() else 'dir' if f.is_dir() else 'undefined'
except OSError:
pass
if t == 'file':
yield f
elif t == 'dir' and depth > 0:
for e in rcollect(f.path, depth - 1, filter):
yield e
评论列表
文章目录