util.py 文件源码

python
阅读 39 收藏 0 点赞 0 评论 0

项目:chi 作者: rmst 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号