from pathlib import Path
from typing import Optional


def get_file_by_type(folder: Path, suffix: str) -> Optional[Path]:
	""" Extracts a file by the suffix. If no files with the suffix are found or more than one file is found returns `None`"""
	if not suffix.startswith('.'):
		suffix = '.' + suffix
	candidates = [i for i in folder.iterdir() if i.suffix == suffix]
	if len(candidates) == 1:
		filename = candidates[0]
	else:
		filename = None
	return filename