utils.py 文件源码

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

项目:cmdchallenge-site 作者: jarv 项目源码 文件源码
def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
    paths = []

    for parent, dirs, files in os.walk(root, topdown=True, followlinks=False):
        parent = os.path.relpath(parent, root)
        if parent == '.':
            parent = ''

        # Remove excluded patterns from the list of directories to traverse
        # by mutating the dirs we're iterating over.
        # This looks strange, but is considered the correct way to skip
        # traversal. See https://docs.python.org/2/library/os.html#os.walk
        dirs[:] = [d for d in dirs if
                   should_check_directory(os.path.join(parent, d),
                                          exclude_patterns, include_patterns)]

        for path in dirs:
            if should_include(os.path.join(parent, path),
                              exclude_patterns, include_patterns):
                paths.append(os.path.join(parent, path))

        for path in files:
            if should_include(os.path.join(parent, path),
                              exclude_patterns, include_patterns):
                paths.append(os.path.join(parent, path))

    return paths
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号