util.py 文件源码

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

项目:autocompose 作者: rapid7 项目源码 文件源码
def get_from_paths(sub_path, file_pattern):
    """
    Search through the AUTOCOMPOSE_PATHs for files in the sub-path which match the given file_pattern
    :param sub_path: The sub-path to look for files in each autocompose path directory.
    :param file_pattern: A pattern to match files.
    :return: A list of files.
    """
    paths = os.environ['AUTOCOMPOSE_PATH'].split(":")
    results = []
    for path in paths:
        try:
            files = os.listdir(path=os.path.join(path, sub_path))
            for file in files:
                if re.fullmatch(file_pattern, file):
                    results.append(os.path.join(path, sub_path, file_pattern))
        except FileNotFoundError:
            pass
    return results
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号