<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def profile_dir(name):
 """Return path to FF profile for a given profile name or path."""

    if name:
        possible_path = Path(name)
        if possible_path.exists():
            return possible_path
    profiles = list(read_profiles())
    try:
        if name:
            profile = next(p for p in profiles if p.name == name)
        else:
            profile = next(p for p in profiles if p.default)
    except StopIteration:
        raise ProfileNotFoundError(name)
    return profile.path