def count_yaml_files()

in dagify/converter/utils.py [0:0]


def count_yaml_files(directory, case_sensitive=True, recursive=False):
    """
    Counts the number of YAML files (.yaml or .yml) in a directory.

    Args:
        directory (str): The path to the directory to search.
        case_sensitive (bool): Whether the search should be case-sensitive (default: True).
        recursive (bool): Whether to search subdirectories recursively (default: False).

    Returns:
        int: The number of YAML files found.
    """

    count = 0
    for files in os.walk(directory):
        for file in files:
            if (case_sensitive and file.endswith(('.yaml', '.yml'))) or \
               (not case_sensitive and file.lower().endswith(('.yaml', '.yml'))):
                count += 1
        if not recursive:
            break  # Stop after the first level if not recursive

    return count