import os
import os
import shutil


def copyfiles(source_path, target_path):
    assert os.path.isdir(
        source_path), 'source_path {} must be ad directory'.format(source_path)
    if not os.path.exists(target_path):
        os.makedirs(target_path)

    for root, dirs, files in os.walk(source_path):
        for file in files:
            src_file = os.path.join(root, file)
            shutil.copy(src_file, target_path)


def search_files(path, label):
    """
    搜索指定路径下带标签的文件
    """
    results = []
    for filename in os.listdir(path):
        if label in filename:
            results.append(os.path.join(path, filename))
    return results
