Source code for pycif.plugins.models.dalecbethy.io.inputs.utils
import glob
import os
[docs]
def find_unique_match(directory, pattern):
"""Find the single file matching ``pattern`` in ``directory``.
Args:
directory (str): directory to search in.
pattern (str): a ``glob`` pattern.
Returns:
str: the single matching file path.
Raises:
FileNotFoundError: if zero, or more than one, file matches.
"""
matches = sorted(glob.glob(os.path.join(directory, pattern)))
if len(matches) != 1:
raise FileNotFoundError(
f"Expected exactly one file matching {pattern!r} in "
f"{directory!r}, found {matches}"
)
return matches[0]