from pathlib import Path


def _check_aux_file(filename):
    """Helper function. Checks if filename exists; if yes, adds a number to
    it."""
    while filename.is_file():
        try:
            name, number = filename.stem.split('_')
            number = int(number) + 1
            filename = Path(f"{name}_{number}{filename.suffix}")
        except ValueError:
            filename = Path(f"{filename.stem}_1{filename.suffix}")
    return filename